ロックを設定している場合、
Intent.ACTION_SCREEN_ON だと画面がオンになった状態で通知がくるので、ロックが外れる前に通知がきてしまいます。画面がオンになったあと、ロックが外れた時に通知を受け取るには
Intent.ACTION_USER_PRESENT を拾うようにします。
public class UserPresentSampleActivity extends Activity {
private static final String TAG = "UserPresentSampleActivity";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
protected void onResume() {
super.onResume();
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_USER_PRESENT);
filter.addAction(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
registerReceiver(mReceiver, filter);
};
@Override
protected void onPause() {
super.onPause();
unregisterReceiver(mReceiver);
};
BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.d(TAG, "mReceiver received : " + action);
if(action.equals(Intent.ACTION_USER_PRESENT)){
}
else if(action.equals(Intent.ACTION_SCREEN_ON)){
}
else if(action.equals(Intent.ACTION_SCREEN_OFF)){
}
}
};
}
D/UserPresentSampleActivity( 9858): mReceiver received : android.intent.action.SCREEN_ON
D/UserPresentSampleActivity( 9858): mReceiver received : android.intent.action.USER_PRESENT
D/UserPresentSampleActivity( 9858): mReceiver received : android.intent.action.SCREEN_OFF
0 件のコメント:
コメントを投稿