如何解决Android 11 中的 deleteNotificationChannel 崩溃
在我的应用程序中,我使用前台服务在应用程序进入后台时显示通知。我通过以下方式创建了一个通知频道:
Popup PROGRAM Format=PE,Model=FLAT,Entry=start:
IMPORT MessageBoxA,Lib=user32.dll
IMPORT ExitProcess,Lib=kernel32.dll
[.data]
Caption db "Message",0
Text db "Hello World",0
MB_OK EQU 0
NULL EQU 0
[.code]
start: push MB_OK
push Caption
push Text
push NULL
call MessageBoxA
push NULL
call ExitProcess
ENDPROGRAM
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = getString(R.string.app_name);
int importance = notificationmanager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel(TransactionsUtil.getNotificationChannelId(this),name,importance);
channel.setDescription("some description");
notificationmanager notificationmanager = getSystemService(notificationmanager.class);
notificationmanager.createNotificationChannel(channel);
}
Notification notification = new NotificationCompat.Builder(this,TransactionsUtil.getNotificationChannelId(this))
.setSmallIcon("some icon")
.setContentTitle("some content")
.setContentText("some content")
.setContentIntent(pendingIntent)
.setChannelId(TransactionsUtil.getNotificationChannelId(this))
.build();
startForeground(NOTIFICATION_ID,notification);
最近,我的应用程序发生了一些与此相关的崩溃;特别是,我有以下错误:
致命异常:java.lang.SecurityException 不允许删除带有前台服务的频道“频道名称”
问题与功能 terminateService 相关,尤其是在 deleteNotificationChannel 中。
由 android.os.remoteexception 引起 远程堆栈跟踪:在 com.android.server.notification.notificationmanagerService$11.enforceDeletingChannelHasNoFgService(notificationmanagerService.java:3859) 在 com.android.server.notification.notificationmanagerService$11.deleteNotificationChannel(notificationmanagerService.java:3872) 在 android.app.Inotificationmanager $Stub.onTransact(Inotificationmanager.java:1813) at android.os.Binder.execTransactInternal(Binder.java:1170) at android.os.Binder.execTransact(Binder.java:1134)
它仅在 Android 11 设备中发生。请问有人有解决方案或建议吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。