gpt4 book ai didi

java - 异常 : java. lang.RuntimeException 在 android.app.ActivityThread.handleReceiver

转载 作者:行者123 更新时间:2023-12-02 05:42:53 30 4
gpt4 key购买 nike

我在 Google Play 中发布了一个应用,但我在 Google Console 中遇到了以下崩溃报告,任何人都可以帮助我了解此问题的根源以及如何解决。

java.lang.RuntimeException: at android.app.ActivityThread.handleReceiver (ActivityThread.java:3523) at android.app.ActivityThread.access$1400 (ActivityThread.java:207) at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1759) at android.os.Handler.dispatchMessage (Handler.java:106) at android.os.Looper.loop (Looper.java:193) at android.app.ActivityThread.main (ActivityThread.java:6863) at java.lang.reflect.Method.invoke (Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:537) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:858) Caused by: java.lang.IllegalStateException: at android.support.v4.media.session.MediaButtonReceiver.onReceive (MediaButtonReceiver.java:124) at android.app.ActivityThread.handleReceiver (ActivityThread.java:3507)

通知:

void startNotify(Context context, String playbackStatus, 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);
}
int icon = R.drawable.ic_pause_white;
Intent playbackAction = new Intent(service, RadioService.class);
playbackAction.setAction(RadioService.ACTION_PAUSE);
PendingIntent action = PendingIntent.getService(service, 1, playbackAction, 0);
if (playbackStatus.equals(PlaybackStatus.PAUSED)) {
icon = R.drawable.ic_play_white;
playbackAction.setAction(RadioService.ACTION_PLAY);
action = PendingIntent.getService(service, 2, playbackAction, 0);

}
Intent stopIntent = new Intent(service, RadioService.class);
stopIntent.setAction(RadioService.ACTION_STOP);
PendingIntent stopAction = PendingIntent.getService(service, 3, stopIntent, 0);

Intent intent = new Intent(service, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP |
Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(service, 0, intent, 0);
notificationManager.cancel(NOTIFICATION_ID);
String PRIMARY_CHANNEL = "PRIMARY_CHANNEL_ID";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager manager = (NotificationManager) service.getSystemService(Context.NOTIFICATION_SERVICE);
String PRIMARY_CHANNEL_NAME = "PRIMARY";
NotificationChannel channel = new NotificationChannel(PRIMARY_CHANNEL, PRIMARY_CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW);
channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
if (manager != null) {
manager.createNotificationChannel(channel);
}
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(service, PRIMARY_CHANNEL)
.setAutoCancel(false)
.setContentTitle(titlesonge)
.setContentText(artist)
.setLargeIcon(BitmapFactory.decodeResource(resources, R.drawable.largeicon))
.setContentIntent(pendingIntent)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setSmallIcon(R.drawable.smallwidth)
.setColor(ContextCompat.getColor(context, R.color.colorneeded))
.addAction(icon, "pause", action)
.addAction(R.drawable.ic_stop_white, "stop", stopAction)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setWhen(System.currentTimeMillis())
.setStyle(new android.support.v4.media.app.NotificationCompat.MediaStyle()
.setMediaSession(service.getMediaSession().getSessionToken())
.setShowActionsInCompactView(0, 1)
.setShowCancelButton(true)
.setCancelButtonIntent(stopAction));
service.startForeground(NOTIFICATION_ID, builder.build());

}

最佳答案

这将分三步解决。1:_ 打开你的 build.gradle(Module: app) 文件。将其添加到应用程序标签下

defaultConfig {
multiDexEnabled true
}

2:_ 如果您使用 appcompact,请在依赖项标签下添加此行

dependencies {
implementation 'com.android.support:multidex:1.0.3'
}

如果您将项目迁移到 AndroidX,则添加此行

dependencies {
implementation 'androidx.multidex:multidex:2.0.1'
}

3:_ 打开所有 Activity java 文件并添加 MultiDex.intall(contextName)

protected void onCreate(Bundle savedInstanceState) {
MultiDex.install(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mine);
`enter code here`
}

关于java - 异常 : java. lang.RuntimeException 在 android.app.ActivityThread.handleReceiver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56121902/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com