1

我有一个LockScreenReceiver扩展BroadcastReceiver类,并且想在每次关闭屏幕时启动 Lock Screen Intent。但是我怎样才能检查Context已经开始给定的活动,所以我不必重新开始。

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
        isScreenOn = false;
        LockServiceManager.getInstance().Initialize(context);
        Intent lockIntent = LockServiceManager.getInstance().getLockScreenActivityIntent();
        lockIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(lockIntent);
    } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
        isScreenOn = true;
        // TODO Start activity if the device has been sleep for a long time.
    } else if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
        Intent lockIntent = LockServiceManager.getInstance().getLockScreenActivityIntent();
        lockIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(lockIntent);
    }
}
4

1 回答 1

1
public void onResume(){   
 Filter = new IntentFilter();
    Filter.addAction("RECEIVED_ACTION");
    activity.registerReceiver(Receiver, Filter);
}

我希望它对你有用。

于 2013-09-13T04:17:00.693 回答