I am trying to make the screen to be always on while my test app is in the foreground with Ongoing Notification running. It works fine when the app is on resume state, but it doesn't work when I hit the home/middle button to put the app on pause state while showing up the Ongoing notification in the notification status bar.
Why getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
does not work in the foreground/pause state?
MainActivity:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.main);
...
NotificationCompat.Builder OnGoingStatusBar = new NotificationCompat.Builder(this);
OnGoingStatusBar.setSmallIcon(R.drawable.image);
OnGoingStatusBar.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
OnGoingStatusBar.setTicker(Test);
OnGoingStatusBar.setContentTitle("Test");
OnGoingStatusBar.setContentText("Testing Message");
OnGoingStatusBar.setWhen(System.currentTimeMillis());
OnGoingStatusBar.setAutoCancel(false);
OnGoingStatusBar.setContent(notificationView).build();
OnGoingStatusBar.setOngoing(true); //Create OnGoing Status Bar
OnGoingStatusBar.setPriority(Notification.PRIORITY_MAX);
NotificationManager.notify(STATUSBAR_ID, OnGoingStatusBar.build());
}