Lock Screen Notifications In Android 5.0

Android Lollipop is running with new features, and one of those is locked screen notifications. Up until this point, lock screen media controls must be defined by the use of a RemoteView, and media control notifications must be built using custom views. Today in this exercise we will see how to use the new MediaStyle for notifications and interacting with a MediaSession for controlling media playback status.

Check the video below which google help has published to show how to change what notifications show up on your lock screen with Android Lollipop.

Let’s now check it with a code sample. Follow the steps below:

Step1: Create a new android project in you Android IDE.

Step2: Write following into your manifest. We will add Media_Content_Control permission to access media style:

 

 

Step3: Create a new class and write following into it. We will need a service to send messages to media player.

 

 

 

Step4: Write following into main activity:

 

 

Step5: Make sure to set your minSDK to API 21 other wise this won’t run.

Step6: Run for output like below:

 

Thanks 🙂

lock1

If you won’t be able to check the output on your emulator’s lock screen don’t wary.. you will get a notification on notification bar like below:

lock2

This is how you can manage your app’s lock screen notification. Checkout my previous blog on How to implement Rate this App feature

Leave a Comment: