1

I've seen many apps do this. Lux comes to mind, also the music player app, and other apps. They display a notification on the lockscreen that has functionality you can interact with. I read lockscreen widgets have been removed on 5.0+, but I still see these apps creating these lockscreen functionality.

I am new to Android development so maybe I am confused on the terminology. Where can I find info on how to create this type of lockscreen functionality.

1 Answer 1

1

HI It can be done using RemoteControlClient part of Android since ICS This part of the code is to intercept media controls.

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void setUpRemoteControlClient() {
Context context = VLCApplication.getAppContext();
AudioManager audioManager = AudioManager)context.getSystemService(AUDIO_SERVICE);
if(Util.isICSOrLater()) {    audioManager.registerMediaButtonEventReceiver(mRemoteControlClientReceiverComponent);
    if (mRemoteControlClient == null) {
        Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
      mediaButtonIntent.setComponent(mRemoteControlClientReceiverComponent);
        PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(context, 0, mediaButtonIntent, 0);
        // create and register the remote control client
        mRemoteControlClient = new RemoteControlClient(mediaPendingIntent);
        audioManager.registerRemoteControlClient(mRemoteControlClient);
    }
    mRemoteControlClient.setTransportControlFlags(
            RemoteControlClient.FLAG_KEY_MEDIA_PLAY |
            RemoteControlClient.FLAG_KEY_MEDIA_PAUSE |
            RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS |
            RemoteControlClient.FLAG_KEY_MEDIA_NEXT |
            RemoteControlClient.FLAG_KEY_MEDIA_STOP);
} else if (Util.isFroyoOrLater()) {
    audioManager.registerMediaButtonEventReceiver(mRemoteControlClientReceiverComponent);
}

}

Sign up to request clarification or add additional context in comments.

2 Comments

Perfect, this is a great starting point. Just what I needed. Thanks!
Thanxx @ Marcelo Mason

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.