@ SuppressWarnings ( "deprecation" ) private void initLockScreenRemoteControlClient ( Context context ) { if ( Build . VERSION . SDK_INT < Build . VERSION_CODES . LOLLIPOP ) { mMediaButtonReceiverComponent = new ComponentName ( mRuntimePackageName , MediaSessionReceiver . class . getName ( ) ) ; mAudioManager . registerMediaButtonEventReceiver ( mMediaButtonReceiverComponent ) ; if ( mRemoteControlClientCompat == null ) { Intent remoteControlIntent = new Intent ( Intent . ACTION_MEDIA_BUTTON ) ; remoteControlIntent . setComponent ( mMediaButtonReceiverComponent ) ; mRemoteControlClientCompat = new RemoteControlClientCompat ( PendingIntent . getBroadcast ( context , 0 , remoteControlIntent , 0 ) ) ; RemoteControlHelper . registerRemoteControlClient ( mAudioManager , mRemoteControlClientCompat ) ; } mRemoteControlClientCompat . setPlaybackState ( RemoteControlClient . PLAYSTATE_PLAYING ) ; mRemoteControlClientCompat . setTransportControlFlags ( RemoteControlClient . FLAG_KEY_MEDIA_PLAY | RemoteControlClient . FLAG_KEY_MEDIA_PAUSE | RemoteControlClient . FLAG_KEY_MEDIA_NEXT | RemoteControlClient . FLAG_KEY_MEDIA_STOP | RemoteControlClient . FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient . FLAG_KEY_MEDIA_PLAY_PAUSE ) ; registerLockScreenReceiver ( context ) ; } }
Initialize the remote control client on the lock screen .