私はリンクhttp://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents/からチュートリアルを使用しており、アンドロイドで画面のオンとオフのデータを取得しようとしています電話。しかしThe method onpause is undefined for the type object
、メソッドで同じエラーが発生しますOnResume
。Android レベルを 10 ~ 17 に設定しました。
そのためのコード全体を次に示します。
package com.example.myfirstapp;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
public class ExampleActivity {
protected void onCreate() {
// INITIALIZE RECEIVER
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
ScreenReceiver mReceiver = new ScreenReceiver();
registerReceiver(mReceiver, filter);
// YOUR CODE
}
private void registerReceiver(ScreenReceiver mReceiver, IntentFilter filter) {
// TODO Auto-generated method stub
}
protected void onPause() {
// WHEN THE SCREEN IS ABOUT TO TURN OFF
if (ScreenReceiver.wasScreenOn) {
// THIS IS THE CASE WHEN ONPAUSE() IS CALLED BY THE SYSTEM DUE TO A SCREEN STATE CHANGE
System.out.println("SCREEN TURNED OFF");
} else {
// THIS IS WHEN ONPAUSE() IS CALLED WHEN THE SCREEN STATE HAS NOT CHANGED
}
super.onPause();
}
protected void onResume() {
// ONLY WHEN SCREEN TURNS ON
if (!ScreenReceiver.wasScreenOn) {
// THIS IS WHEN ONRESUME() IS CALLED DUE TO A SCREEN STATE CHANGE
System.out.println("SCREEN TURNED ON");
} else {
// THIS IS WHEN ONRESUME() IS CALLED WHEN THE SCREEN STATE HAS NOT CHANGED
}
super.onResume();
}
}