标签: remoteserviceexception

startForegroundService()没有调用startForeground(),但确实如此

我有Context.startForegroundService() did not then call Service.startForeground()我的Android服务,但我无法弄清楚它为什么会发生.

我的应用程序用于媒体流,只有当您从前台通知暂停(将其转换为常规通知)时才会出现此错误,然后您将通知刷掉,这是为了停止我的服务.

这里就是唯一的方法startForegroundService,startForegroundstopForeground方法被称为:

private void configureServiceState(long action) {
        if (action == PlaybackStateCompat.ACTION_PLAY) {
            if (!mServiceInStartedState) {
                ContextCompat.startForegroundService(
                        StreamingService.this,
                        new Intent(
                                StreamingService.this,
                                StreamingService.class));
                mServiceInStartedState = true;
            } startForeground(NOTIFICATION_ID,
                    buildNotification(PlaybackStateCompat.ACTION_PAUSE));
        } else if (action == PlaybackStateCompat.ACTION_PAUSE) {
            stopForeground(false);

            NotificationManager mNotificationManager
                    = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

            assert mNotificationManager != null;
            mNotificationManager
                    .notify(NOTIFICATION_ID,
                            buildNotification(PlaybackStateCompat.ACTION_PLAY));
        } else if (action == PlaybackStateCompat.ACTION_STOP) {
            mServiceInStartedState = false;
            stopForeground(true);
            stopSelf();
        }
    }
Run Code Online (Sandbox Code Playgroud)

这里是我的通知的删除意图设置的地方:

.setDeleteIntent(
                        MediaButtonReceiver.buildMediaButtonPendingIntent(
                                this, PlaybackStateCompat.ACTION_STOP)); …
Run Code Online (Sandbox Code Playgroud)

java android android-notifications foreground-service remoteserviceexception

10
推荐指数
2
解决办法
5197
查看次数

onCreate() 和 onStartCommand() 中的 startForeground()

我遇到了 Playstore 报告的大量异常。来自 Android P 的 RemoteServiceException。

我正在创建 android 前台服务,然后调用 startForegound(with channel)。

但 99.9% 只有 9.0(android P) 用户报告 RemoteServiceException。我检查了我是否为该服务制作了通知渠道。我还检查了我是否在 OREO 之后为 os 调用了 startForegroundService。

每个代码都没有问题。

但是我发现我多次调用 startForegroundService() ,但是在第一次创建 Service 时只调用了一次 onCreate() 。所以 onCreate() 中的 startForeground() 只被调用一次。

但是,如果我将 startForeground() 放在 onStartCommand() 中,那么它的调用次数也将与我调用 startForegroundService() 的次数一样多。因为每当您调用 startService/startForegroundService 时它也会被调用(即使已经创建了 Service 的实例)。

你认为这是异常的原因吗?

而 mboy 对/sf/answers/3587621901/的评论 也说了类似的话。

android foreground-service remoteserviceexception android-9.0-pie

10
推荐指数
1
解决办法
1356
查看次数

Context.startForegroundService()然后没有调用Service.startForeground()?

我的用户报告了数百次崩溃,但仍然无法找到解决方法.这些崩溃来自Android 8(三星,华为,谷歌).

我得到这两个崩溃:

Fatal Exception: android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground()
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1881)
       at android.os.Handler.dispatchMessage(Handler.java:105)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6938)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Run Code Online (Sandbox Code Playgroud)

另一个:

Fatal Exception: android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground()
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2104)
       at android.os.Handler.dispatchMessage(Handler.java:108)
       at android.os.Looper.loop(Looper.java:166)
       at android.app.ActivityThread.main(ActivityThread.java:7428)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
Run Code Online (Sandbox Code Playgroud)

我假设这些崩溃是相同的,但正如您所看到的,堆栈跟踪显示不同的代码行.

问题是我无法重现它,我的设备和模拟器上的一切正常.但是,我(不知何故)通过创建服务而不调用类startForeground()内来复制Service.

我无法"捕获"异常,因为它在创建服务5秒后立即来自系统级别.

我做了什么,我创建了一个方法,它创建一个粘性通知并调用startForeground方法(我的服务类):

private void startWithNotification() {
     Resources res = getResources();
     String title = res.getString(R.string.application_name);

     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
         createChannels();
     }

     NotificationCompat.Builder …
Run Code Online (Sandbox Code Playgroud)

android foreground-service remoteserviceexception

9
推荐指数
0
解决办法
2210
查看次数

为什么在创建/更新通知时会收到RemoteServiceException?

背景

我有一个业余时间的应用程序,我已经工作了几年了(在这里),并且我尝试尽可能多地处理崩溃(我讨厌看到崩溃报告!)。

问题

最近发生的一次崩溃似乎很新:

android.app.RemoteServiceException: 
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1768)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loop (Looper.java:164)
  at android.app.ActivityThread.main (ActivityThread.java:6494)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:438)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:807)
Run Code Online (Sandbox Code Playgroud)

这就是我所看到的...

似乎仅适用于Android 8.1。由于该应用程序必须非常受欢迎,因此我确信它仅会在Android 8.1上出现。

我尝试过的

在互联网上搜索,我可以找到类似的崩溃,但是在所有崩溃中,它们都有更多线索。

因此,我试图回顾一下最近所做的更改。唯一的变化是将支持库迁移到Android-X。其余的更改很小,我认为它们不是造成更改的原因。

由于没有更多线索,我决定在此处报告有关Android-X的部分(如有需要,请在此处提供更多信息),因为我不认为这是因为我试图解决问题,并且看起来像是非常具体。

后来,我集成了Firebase Crashlytics,并在每个这样的日志上方获得了这个小提示:

Fatal Exception: android.app.RemoteServiceException
Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=channel_id__app_monitor pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x40 color=0x00000000 category=service vis=SECRET)
Run Code Online (Sandbox Code Playgroud)

这很奇怪,因为我确实正确打开了该服务,否则它将根本无法工作,这尤其奇怪,它仅在Android 8.1上发生,而不是在8.0上发生,这对如何操作有相同的要求启动前台服务。

这个有问题的通知是有关我用于全局监视与应用程序相关的事件的前台服务的通知(仅来自具有广播接收器限制的Android O)。更新了2种情况:

  1. 区域变更
  2. 在某个对话框上的某个复选框上打勾,该复选框会在某个时间点出现(单击该对话框时)。

当我测试了这两个功能后,它们在Android 8.0和8.1上都可以正常工作。

这是创建/更新通知的代码:

    @JvmStatic
    fun getUpdatedAppMonitorNotification(context: Context): Notification { …
Run Code Online (Sandbox Code Playgroud)

android android-notifications android-8.1-oreo remoteserviceexception

8
推荐指数
1
解决办法
2197
查看次数

RemoteServiceException:无法在所有具有 oreo 和 pie 的 OnePlus 设备上传送广播

在过去的 3-4 个月中,我一直在 Crashlytics 中看到这种崩溃,仅适用于具有奥利奥和馅饼的 OnePlus 制造的设备(一个、3、5,5T、6、6T)。以前的android版本没有发生这种情况。

Fatal Exception: android.app.RemoteServiceException: can't deliver broadcast
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1844)
   at android.os.Handler.dispatchMessage(Handler.java:106)
   at android.os.Looper.loop(Looper.java:193)
   at android.app.ActivityThread.main(ActivityThread.java:6892)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Run Code Online (Sandbox Code Playgroud)

我在stackoverflow中查看了不同的帖子,重新检查了与Firebase Messaging相关的所有代码并更新到最新版本的firebase,但没有运气。如果有人遇到同样的崩溃,请帮忙。提前致谢。

编辑 1:可能的原因可能是,我将通知图标放在 mipmap 而不是 drawable 中。 https://forums.oneplus.com/threads/app-notification-provokes-continues-system-ui-crashes-and-possible-corruption-of-the-os.713575/

Android Oreo 通知崩溃系统 UI

https://issuetracker.google.com/issues/69109923

但是,如果我将通知放在 drawable 中,那么我该如何修复资源 ID,以免再次遇到下面提到的问题(为了修复资源 ID,我将通知图标从 drawable 移到了 mipmap)。最近发布的 gradle 忽略了 public.xml:

如何修复:android.app.RemoteServiceException:从包中发布的错误通知*:无法创建图标:StatusBarIcon

notifications android broadcast android-resources remoteserviceexception

6
推荐指数
0
解决办法
1702
查看次数

如何修复“android.app.RemoteServiceException”?

我的应用程序出现“android.app.RemoteServiceException”异常。我使用“JobScheduler”代替“Service”。除了 OPPO 8.1 之外,它还有效。这就是我收到的所有消息。

android.app.ActivityThread$H.handleMessage(ActivityThread.java:1987)
android.os.Handler.dispatchMessage(Handler.java:106)
android.os.Looper.loop(Looper.java:187)
android.app.ActivityThread.main(ActivityThread.java:7025)
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:514)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:888)

Run Code Online (Sandbox Code Playgroud)

android remoteserviceexception

6
推荐指数
1
解决办法
1357
查看次数