我在我的 android 设备崩溃时遇到系统 UI 问题。每次我尝试激活 mediaSessionCompat 时都会发生这种情况。我已经研究过以下帖子的建议: https ://github.com/firebase/quickstart-android/issues/382 但没有用。下面只是一个包含更多信息的简单代码示例。
MediaSessionCompat mediaSessionCompat;
ComponentName mediaButtonReceiver = new ComponentName(getApplicationContext(), MediaButtonReceiver.class);
mediaSessionCompat = new MediaSessionCompat(getApplicationContext(), "Tag", mediaButtonReceiver, null);
mediaSessionCompat.setCallback(mediaSessionCallback);
mediaSessionCompat.setFlags(
MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS |
MediaSessionCompat.FLAG_HANDLES_QUEUE_COMMANDS);
Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
mediaButtonIntent.setClass(this, MediaButtonReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0);
mediaSessionCompat.setMediaButtonReceiver(pendingIntent);
mediaSessionCompat.setRatingType(RatingCompat.RATING_NONE);
mediaSessionCompat.setShuffleMode(PlaybackStateCompat.SHUFFLE_MODE_NONE);
mediaSessionCompat.setQueue(mediaQueueManager.getMediaQueue());
MediaSessionCompat.Token token = mediaSessionCompat.getSessionToken();
setSessionToken(token);
mediaSessionCompat.setActive(true); // this is where the error occurs
我试图禁用所有图标,并将它们设置为我通过图像资产创建器创建的旧图标。
我正在构建应用程序:
- minSdkVersion 21
- targetSdkVersion 27