I want to see a fullscreen activity when I receive a push notification. It 
works fine when the screen is on/unlocked. But when the screen is off and 
locked, I dont see the activity. Please help

// Push notification received public class PushNotificationReceiver extends 
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);
}
}

// Fullscreen activity as notification

 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();
    }
}

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
To post to this group, send email to android-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/2a9c395a-abc0-45bd-b16c-907d1ea99d20%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to