锁定和屏幕关闭时全屏通知(不工作)

时间:2016-07-26 17:28:12

标签: android-wake-lock

我希望在收到推送通知时看到全屏活动。 屏幕打开/解锁时工作正常。 但是当屏幕关闭并锁定时,我看不到活动。 请帮忙

//推送收到通知     公共类PushNotificationReceiver扩展了WakefulBroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
 Intent pushIntent = new Intent(context.getApplicationContext(), CustomNotificationActivity.class);
                    pushIntent.putExtra(CustomNotificationActivity.EXTRA_PUSH_MESSAGE, String.valueOf(pushMessage));
                    pushIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    context.startActivity(pushIntent);
}
}

//作为通知的全屏活动

 CustomNotificationActivity.java
    public class CustomNotificationActivity extends Activity {
  private KeyguardManager.KeyguardLock lock;
    private PowerManager.WakeLock wakeLock;

    @Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        PowerManager pwm = (PowerManager) getSystemService(POWER_SERVICE);
        wakeLock = pwm.newWakeLock(PowerManager.FULL_WAKE_LOCK, getClass().getSimpleName());
        wakeLock.acquire();
        KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
        lock = keyguardManager.newKeyguardLock(getClass().getSimpleName());
        lock.disableKeyguard();
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
...
...
..

}

   @Override
    public void onPause() {
        super.onPause();
        wakeLock.release();
        lock.reenableKeyguard();
        ......
        finish();
    }
}

0 个答案:

没有答案