1

I want to show a different notification layout in lock screen. I am using Remote Views and I want to know if I can create two different notifications from the notifications creator class depending if its the lock screen or not.

Exists any flag for this?

Thank you.

Jaume Colom
  • 1,701
  • 3
  • 11
  • 6

2 Answers2

0

Edit: perhaps this tutorial can help you

http://karanbalkar.com/2014/11/tutorial-90-implement-media-style-notifications-in-android/

Old: You could create 2 Notifications with different priorities as described in

http://developer.android.com/design/patterns/notifications.html

and use the HIGH priority for the Notification shown on the Lock-Screen.

The problem is that you want to create a notification that is ONLY visible on the Lockscreen. This feature itself does not exist. With the above mentioned solution you would have both Notifications shown in the unlocked screen.

You could listen for the screenlock as shown in this answer:

Android - detect phone unlock event, not screen on

Then you could dismiss the Notification with the high priority and only use the Notification with default-prio, and update this notification if necessary.

If you would describe better what you want to accomplish i can give you a code sample

Community
  • 1
  • 1
Malte
  • 589
  • 5
  • 24
0

YES you can do it.

you can use Settings.System.putString(context.getContentResolver(), Settings.System.NEXT_ALARM_FORMATTED, yourMessage); to show notification if screen is lock. and if screen is not locked then then use

NotificationCompat.Builder mBuilder =   new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.ic_launcher) // notification icon
        .setContentTitle("Notification!") // title for notification
        .setContentText("Hello word") // message for notification
        .setAutoCancel(true); // clear notification after click
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(this,0,intent,Intent.FLAG_ACTIVITY_NEW_TASK);
mBuilder.setContentIntent(pi);
NotificationManager mNotificationManager =
                    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());

and now you can show notification.and your detecting that your screen is locked or not then you can use this code

KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
boolean locked = km.inKeyguardRestrictedInputMode();

enjoy your code:)

John smith
  • 1,781
  • 17
  • 27