RemoteControlClient在服务关闭后继续显示

时间:2015-09-14 12:05:19

标签: android lockscreen

RemoteControlClient在服务关闭后继续显示 我已经实现了RemoteControlClient并且它正常工作,我一直试图在我的应用和服务关闭后搜索关闭RemoteControlClient的方式我无法找到任何解决方案。一旦我关闭我的应用程序或服务它仍然继续显示RemoteControlClient在锁屏上。

我已使用finish()

关闭了我的活动

我的服务使用stopSelf()

here is the code for starting the RemoteControlClient 

    ComponentName myEventReceiver = new ComponentName(
                    getApplicationContext().getPackageName(),
                    MyRemoteControlEventReceiver.class.getName());

            AudioManager myAudioManager = (AudioManager) getApplicationContext()
                    .getSystemService(Context.AUDIO_SERVICE);

            myAudioManager.registerMediaButtonEventReceiver(myEventReceiver);
            // build the PendingIntent for the remote control client

            Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
            mediaButtonIntent.setComponent(myEventReceiver);
            PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(
                    getApplicationContext(), 0, mediaButtonIntent, 0);
            // create and register the remote control client
             myRemoteControlClient = new RemoteControlClient(
                    mediaPendingIntent);

            myRemoteControlClient.setTransportControlFlags(
            RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE
            |RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS
            | RemoteControlClient.FLAG_KEY_MEDIA_NEXT);
            myAudioManager.registerRemoteControlClient(myRemoteControlClient);

            myRemoteControlClient
                    .editMetadata(true)
                    .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, "title")
                        .apply();
            myRemoteControlClient
                    .setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
            // Request audio focus for playback
            int result = myAudioManager.requestAudioFocus(this,
                    AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);

我的问题是在关闭应用程序或关闭服务后如何关闭RemoteControlClient

是否有任何方法需要像我们为服务和活动那样进行调用。

0 个答案:

没有答案