I have an app which receives push notifications from custom webserver using the new gcm api. Everything works fine. However, I want to display the notifications on the lock screen too.
I googled around and found this post, but it won't help: Android how to show notification on screen
Is there any simple way to achieve this? Thanks for your help!
EDIT //
Here is some code.
In the GCMHandler I use this snippet to show the notification:
private void sendNotification() {
mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("message", message);
intent.putExtra("pbid", pbid);
intent.putExtra("alarm", alarm);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(alarm ? getString(R.string.txt_alarm_message_title) : getString(R.string.txt_info_message_title))
.setContentText(message);
// play alarm tone
if (alarm) playRingtone();
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
And in the application's main activity I used the code from the post above:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
setContentView(R.layout.act_main);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON, WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED, WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
...
}
The problem is, that the notification is shown, but not available on the lock screen. If the screen is screen is locked, no push notification will be received ;(