java.lang.IllegalStateException android.support.v4.media.session.MediaButtonReceiver.onReceive

java.lang.IllegalStateException android.support.v4.media.session.MediaButtonReceiver.onReceive,java,android,exoplayer,Java,Android,Exoplayer,我使用下面的代码为暂停和播放操作创建了一个通知控制器,当我在手机上进行测试时,它工作正常,但在ANRs&Crash下的Google Play Console中,我得到了以下报告: java.lang.RuntimeException: 位于android.app.ActivityThread.HandlerReceiver(ActivityThread.java:3618) 在android.app.ActivityThread.access上$1300(ActivityThread.java:

我使用下面的代码为暂停和播放操作创建了一个通知控制器,当我在手机上进行测试时,它工作正常,但在ANRs&Crash下的Google Play Console中,我得到了以下报告:

java.lang.RuntimeException: 位于android.app.ActivityThread.HandlerReceiver(ActivityThread.java:3618) 在android.app.ActivityThread.access上$1300(ActivityThread.java:240) 在android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 位于android.os.Handler.dispatchMessage(Handler.java:106) 位于android.os.Looper.loop(Looper.java:214) 位于android.app.ActivityThread.main(ActivityThread.java:7076) 位于java.lang.reflect.Method.invoke(Method.java) 在com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run上 (RuntimeInit.java:494) 位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965) 原因:java.lang.IllegalStateException: 在android.support.v4.media.session.MediaButtonReceiver.onReceive (MediaButtonReceiver.java:74) 位于android.app.ActivityThread.HandlerReceiver(ActivityThread.java:3609) 在android.app.ActivityThread.access上$1300(ActivityThread.java:240) 在android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 位于android.os.Handler.dispatchMessage(Handler.java:106) 位于android.os.Looper.loop(Looper.java:214) 位于android.app.ActivityThread.main(ActivityThread.java:7076) 位于java.lang.reflect.Method.invoke(Method.java) 在com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run上 (RuntimeInit.java:494) 位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)

一旦创建

@Override
    public void onCreate() {
        super.onCreate();
        String strAppName = getResources().getString(R.string.app_name);
        String strLiveBroadcast = getResources().getString(R.string.live_broadcast);
        onGoingCall = false;
        audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        notificationManager = new MediaNotificationManager(this);
        wifiLock = ((WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE))
                .createWifiLock(WifiManager.WIFI_MODE_FULL, "mcScPAmpLock");
        mediaSession = new MediaSessionCompat(this, getClass().getSimpleName());
        transportControls = mediaSession.getController().getTransportControls();
        mediaSession.setActive(true);
        mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
        mediaSession.setMetadata(new MediaMetadataCompat.Builder()
                .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, "...")
                .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, strAppName)
                .putString(MediaMetadataCompat.METADATA_KEY_TITLE, strLiveBroadcast)
                .build());
        mediaSession.setCallback(mediasSessionCallback);
        DefaultTrackSelector trackSelector = new DefaultTrackSelector();
        exoPlayer = ExoPlayerFactory.newSimpleInstance(getApplicationContext(), trackSelector);
        exoPlayer.addListener(this);
        registerReceiver(becomingNoisyReceiver, new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY));
        status = PlaybackStatus.IDLE;
    }
   void exoPlayerNotification(Context context, SimpleExoPlayer exoPlayer, 
 String title) {
        String titlesonge;
        String artist;
        try {
            titlesonge = StringUtils.substringBefore(title, " - ");
            artist = StringUtils.substringAfter(title, " - ");
        } catch (Exception e) {
            titlesonge = title.substring(0, title.indexOf(" - "));
            artist = title.substring(title.lastIndexOf(" - ") - 1);
        }
        String finalArtist = artist;
        String finalTitlesonge = titlesonge;
        PlayerNotificationManager mPlayerNotificationManager = PlayerNotificationManager.createWithNotificationChannel(
                context,
                "PRIMARY_CHANNEL_ID",
                R.string.plaza,
                NOTIFICATION_ID,
                new PlayerNotificationManager.MediaDescriptionAdapter() {
                    @Override
                    public String getCurrentContentTitle(Player player) {
                        return finalArtist;
                    }

                    @Nullable
                @Override
                public PendingIntent createCurrentContentIntent(Player player) {
                    Intent intent = new Intent(service, MainActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
                            Intent.FLAG_ACTIVITY_SINGLE_TOP |
                            Intent.FLAG_ACTIVITY_NEW_TASK);
                    return PendingIntent.getActivity(service, 0, intent,
                            PendingIntent.FLAG_UPDATE_CURRENT);
                }

                @Override
                public String getCurrentContentText(Player player) {
                    return finalTitlesonge;
                }

                @Nullable
                @Override
                public Bitmap getCurrentLargeIcon(Player player, PlayerNotificationManager.BitmapCallback callback) {
                    return BitmapFactory.decodeResource(service.getResources(), R.drawable.largeicon);
                }

                @Nullable
                @Override
                public String getCurrentSubText(Player player) {
                    return null;
                }
            }
    );
    mPlayerNotificationManager.setUseNavigationActions(false);
    mPlayerNotificationManager.setFastForwardIncrementMs(0);
    mPlayerNotificationManager.setRewindIncrementMs(0);
    mPlayerNotificationManager.setColorized(true);
    mPlayerNotificationManager.setColor(0xFFBDBDBD);
    mPlayerNotificationManager.setUseChronometer(true);
    mPlayerNotificationManager.setOngoing(true);
    mPlayerNotificationManager.setPriority(NotificationCompat.PRIORITY_MAX);
    mPlayerNotificationManager.setUsePlayPauseActions(true);
    mPlayerNotificationManager.setSmallIcon(R.drawable.smallwidth);
    mPlayerNotificationManager.setNotificationListener(new PlayerNotificationManager.NotificationListener() {
        @Override
        public void onNotificationStarted(int notificationId, Notification notification) {
            service.startForeground(notificationId, notification);
        }

        @Override
        public void onNotificationCancelled(int notificationId) {
            service.stopSelf();
            cancelNotify();
        }
    });
    mPlayerNotificationManager.setPlayer(exoPlayer);
}
通知

@Override
    public void onCreate() {
        super.onCreate();
        String strAppName = getResources().getString(R.string.app_name);
        String strLiveBroadcast = getResources().getString(R.string.live_broadcast);
        onGoingCall = false;
        audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        notificationManager = new MediaNotificationManager(this);
        wifiLock = ((WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE))
                .createWifiLock(WifiManager.WIFI_MODE_FULL, "mcScPAmpLock");
        mediaSession = new MediaSessionCompat(this, getClass().getSimpleName());
        transportControls = mediaSession.getController().getTransportControls();
        mediaSession.setActive(true);
        mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
        mediaSession.setMetadata(new MediaMetadataCompat.Builder()
                .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, "...")
                .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, strAppName)
                .putString(MediaMetadataCompat.METADATA_KEY_TITLE, strLiveBroadcast)
                .build());
        mediaSession.setCallback(mediasSessionCallback);
        DefaultTrackSelector trackSelector = new DefaultTrackSelector();
        exoPlayer = ExoPlayerFactory.newSimpleInstance(getApplicationContext(), trackSelector);
        exoPlayer.addListener(this);
        registerReceiver(becomingNoisyReceiver, new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY));
        status = PlaybackStatus.IDLE;
    }
   void exoPlayerNotification(Context context, SimpleExoPlayer exoPlayer, 
 String title) {
        String titlesonge;
        String artist;
        try {
            titlesonge = StringUtils.substringBefore(title, " - ");
            artist = StringUtils.substringAfter(title, " - ");
        } catch (Exception e) {
            titlesonge = title.substring(0, title.indexOf(" - "));
            artist = title.substring(title.lastIndexOf(" - ") - 1);
        }
        String finalArtist = artist;
        String finalTitlesonge = titlesonge;
        PlayerNotificationManager mPlayerNotificationManager = PlayerNotificationManager.createWithNotificationChannel(
                context,
                "PRIMARY_CHANNEL_ID",
                R.string.plaza,
                NOTIFICATION_ID,
                new PlayerNotificationManager.MediaDescriptionAdapter() {
                    @Override
                    public String getCurrentContentTitle(Player player) {
                        return finalArtist;
                    }

                    @Nullable
                @Override
                public PendingIntent createCurrentContentIntent(Player player) {
                    Intent intent = new Intent(service, MainActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
                            Intent.FLAG_ACTIVITY_SINGLE_TOP |
                            Intent.FLAG_ACTIVITY_NEW_TASK);
                    return PendingIntent.getActivity(service, 0, intent,
                            PendingIntent.FLAG_UPDATE_CURRENT);
                }

                @Override
                public String getCurrentContentText(Player player) {
                    return finalTitlesonge;
                }

                @Nullable
                @Override
                public Bitmap getCurrentLargeIcon(Player player, PlayerNotificationManager.BitmapCallback callback) {
                    return BitmapFactory.decodeResource(service.getResources(), R.drawable.largeicon);
                }

                @Nullable
                @Override
                public String getCurrentSubText(Player player) {
                    return null;
                }
            }
    );
    mPlayerNotificationManager.setUseNavigationActions(false);
    mPlayerNotificationManager.setFastForwardIncrementMs(0);
    mPlayerNotificationManager.setRewindIncrementMs(0);
    mPlayerNotificationManager.setColorized(true);
    mPlayerNotificationManager.setColor(0xFFBDBDBD);
    mPlayerNotificationManager.setUseChronometer(true);
    mPlayerNotificationManager.setOngoing(true);
    mPlayerNotificationManager.setPriority(NotificationCompat.PRIORITY_MAX);
    mPlayerNotificationManager.setUsePlayPauseActions(true);
    mPlayerNotificationManager.setSmallIcon(R.drawable.smallwidth);
    mPlayerNotificationManager.setNotificationListener(new PlayerNotificationManager.NotificationListener() {
        @Override
        public void onNotificationStarted(int notificationId, Notification notification) {
            service.startForeground(notificationId, notification);
        }

        @Override
        public void onNotificationCancelled(int notificationId) {
            service.stopSelf();
            cancelNotify();
        }
    });
    mPlayerNotificationManager.setPlayer(exoPlayer);
}

如何解决此问题

您找到解决方案了吗?我有完全一样的东西。