android.app.ContextImpl.startServiceCommon 处的 java.lang.IllegalStateException

2024-03-27

我在 Playstore 上有一个应用程序,最近我仅在 Android 8.0 设备上遇到这些错误。请参阅我从 Google Play Console 收到的 Android 堆栈跟踪。我还包括了 firebase 助手类。提前致谢 :)

java.lang.IllegalStateException: 
  at android.app.ContextImpl.startServiceCommon (ContextImpl.java:1737)
  at android.app.ContextImpl.startService (ContextImpl.java:1693)
  at android.content.ContextWrapper.startService (ContextWrapper.java:650)
  at android.support.v4.content.WakefulBroadcastReceiver.startWakefulService (Unknown Source:22)
  at com.google.firebase.iid.zzg.zzg (Unknown Source:9)
  at com.google.firebase.iid.zzg.zzb (Unknown Source:78)
  at com.google.firebase.iid.zzg.zzf (Unknown Source:2)
  at com.google.firebase.iid.FirebaseInstanceIdService.a (Unknown Source:23)
  at com.google.firebase.iid.FirebaseInstanceIdService.a (Unknown Source:34)
  at com.google.firebase.iid.FirebaseInstanceId.<init> (Unknown Source:31)
  at com.google.firebase.iid.FirebaseInstanceId.getInstance (Unknown Source:47)
  at com.google.firebase.iid.FirebaseInstanceId.getInstance (Unknown Source:4)
  at com.google.firebase.iid.FirebaseInstanceIdService.zza (Unknown Source:14)
  at com.google.firebase.iid.FirebaseInstanceIdService.handleIntent (Unknown Source:35)
  at com.google.firebase.iid.zzb$zza$1.run (Unknown Source:24)
  at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1162)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:636)
  at java.lang.Thread.run (Thread.java:784) 

MyFirebaseInstanceIdService 类

public class MyFirebaseInstanceIdService extends FirebaseInstanceIdService {

    private static final String REG_TOKEN = "REG_TOKEN";

    @Override
    public void onTokenRefresh() {

        String recent_token = FirebaseInstanceId.getInstance().getToken();
        Log.d(REG_TOKEN, recent_token);

    }
}

MyFirebaseMessagingService 类

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Intent intent = new Intent(getApplicationContext(), OnlineActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_ONE_SHOT);
        NotificationCompat.Builder notifcationBuilder = new NotificationCompat.Builder(getApplicationContext());
        notifcationBuilder.setContentTitle("Dictionary Notification");
        notifcationBuilder.setContentText(remoteMessage.getNotification().getBody());
        notifcationBuilder.setAutoCancel(true);
        notifcationBuilder.setSmallIcon(R.mipmap.ic_launcher);
        notifcationBuilder.setContentIntent(pendingIntent);
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        if (notificationManager != null) {
            notificationManager.notify(0, notifcationBuilder.build());
        }

    }
}

摇篮文件:

dependencies {
    implementation 'com.android.support:support-vector-drawable:27.1.1'

    implementation 'com.google.android.gms:play-services-plus:15.0.1'
    implementation fileTree(dir: 'libs', include: ['*.jar'])


    implementation 'com.google.firebase:firebase-core:16.0.1'

    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.github.Hitomis:CircleMenu:v1.1.0'


    implementation 'com.squareup.okhttp3:okhttp:3.10.0'
    implementation 'com.google.code.gson:gson:2.8.2'
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    implementation 'com.mindorks:placeholderview:0.2.7'


    implementation('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
        transitive = true;
    }
    testImplementation 'junit:junit:4.12'


    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.github.amlcurran.showcaseview:library:5.4.3'
    implementation 'com.pacioianu.david:ink-page-indicator:1.2.0'
    implementation 'com.github.zcweng:switch-button:0.0.3@aar'


    // Google
    implementation 'com.google.android.gms:play-services-auth:15.0.1'

    // Firebase
    implementation 'com.google.firebase:firebase-database:16.0.1'
    implementation 'com.google.firebase:firebase-auth:16.0.2'
    implementation 'com.google.firebase:firebase-storage:16.0.1'
    implementation 'com.firebaseui:firebase-ui-database:1.2.0'
    implementation 'com.google.firebase:firebase-messaging:17.1.0'



    implementation 'com.github.bumptech.glide:glide:3.7.0'
    implementation 'de.hdodenhof:circleimageview:1.3.0'
    implementation 'com.codemybrainsout.onboarding:onboarder:1.0.4'
    implementation 'com.google.android.gms:play-services-vision:15.0.2'
    implementation 'com.huxq17.android:SwipeCardsView:1.3.5'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.airbnb.android:lottie:2.5.4'


}

apply plugin: 'com.google.gms.google-services'

发生这种情况的原因可能是 Android 8 Oreo 中引入了新的后台服务限制,请参阅:https://developer.android.com/about/versions/oreo/android-8.0-changes#back-all https://developer.android.com/about/versions/oreo/android-8.0-changes#back-all

一种建议的解决方案是使用 JobScheduler(我就是这样做的),但这似乎不适合 Firebase 消息接收器,因此您可能需要检查文档是否有一些关于此的提示。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

android.app.ContextImpl.startServiceCommon 处的 java.lang.IllegalStateException 的相关文章

  • Spring Boot,使用 EhCache 进行缓存

    我需要在我的应用程序中缓存一些数据 我正在考虑使用 Ehcache 我有几个问题 Ehcache需要另外一台服务器吗 我需要其他客户端来使用 Ehcache 吗 Ehcache 如何与多个实例配合使用 是否有可能使用 Ehcache 创建类
  • 如何防止机器人程序和垃圾邮件 API 请求?

    我正在使用react native 开发一个Android 应用程序 该应用程序与我正在为该应用程序开发的API 进行通信 该 API 是使用 Laravel 和 Laravel Passport 构建的 我知道 Android 应用程序可
  • 带有 CONTAINS 查询的PreparedStatement

    我有一个查询需要连续运行 28000 次 所以我认为使用准备好的语句可能是一个聪明的主意 这是我的查询 String requestWithFirstName SELECT SE ELEMENT ID SE LASTNAME SE FIRS
  • Cordova Android 应用程序中的网页不可用

    编辑 我一直在解决这个问题并回顾我的所有步骤 我很乐意缩小这个问题的规模 并在令人困惑的情况下获得更多确切的细节 目前 我觉得 Keycloak 似乎只想将我重定向到 https 据我所知 这应该是 Wildfly 服务器配置问题 编辑 我
  • 如何使用 gradle 动态切换/更改 testInstrumentationRunner

    我的项目有两组不同的测试 一组仅使用默认值运行AndroidJUnitRunner另一个必须使用自定义实现来运行TestRunner extends MonitoringInstrumentation 目前我切换testInstrument
  • 如何从 Java 类调用 Kotlin 类

    我需要将意图从 java 活动传递到 Kotlin 活动 Java活动ProfileActivity class Intent selectGameIntent new Intent ProfileActivity this kotlin
  • android拦截最近的应用程序按钮

    我有一个针对儿童的应用程序 我不希望他们能够单击 最近使用的应用程序 按钮 看起来像两个矩形叠在一起的按钮 我正在负责捕获后退按钮和主页按钮 并且我已经搜索并阅读了很多有关尝试捕获 最近的应用程序 按钮的信息 但大多数人说你不能 或者他们的
  • 处理网络视图中的链接

    我有我的WebView加载网络视图中的所有链接 但是当我选择电子邮件链接时 它会尝试将其加载到网络视图中 而不是在手机上启动电子邮件应用程序 我该如何解决这个问题 链接是mailto 电子邮件受保护 cdn cgi l email prot
  • 如何将 JAVAX-WS 端点绑定更改为 SOAP 1.2?

    我正在使用发布测试 WS 实现Endpoint publish 用于在 Visual Studio 中使用 根据文档 http metro java net nonav 1 2 docs endpoint html默认的 SOAP 绑定是1
  • java:验证 GUI 中的所有文本字段是否已完成

    我正在尝试创建一个允许某人设置帐户的 GUI 我想验证按下创建帐户按钮时所有文本字段是否完整 做这个的最好方式是什么 我正在附加我的代码 但我对文本字段是否完整的验证不起作用 参见下面的代码 public class GUIaccounts
  • Java 统一编码

    A Java char is 2 bytes http java sun com docs books tutorial java nutsandbolts datatypes html 最大大小为 65 536 但有95 221 http
  • 运行 JAR 时“JCE 无法验证提供者 BC”

    在我的 scala 项目中我使用 org bouncycastle bcprov jdk14 1 51 用于密码学 如果它在 Scala IDE 中测试我的项目 它工作得很好 但是一旦我制作了一个 JAR 并尝试通过以下方式运行它java
  • 使用 jenkins.Creating .apk 文件生成 android 版本

    我正在使用 Jenkins 在 mac 上持续集成 android 应用程序 但是我无法使用 Jenkins 生成 apk 文件 就像我们在 iOS 应用程序中创建 ipa 一样 创建用于在 mac 上分发的 apk 文件的配置是什么 您可
  • 使用 System.currentTimeMillis() 每秒运行一次代码

    我试图使用 System currentTimeMillis 每秒运行一行代码 代码 while true long var System currentTimeMillis 1000 double var2 var 2 if var2 1
  • java.net.ServerSocket.accept () 在 Android 上不返回

    我正在尝试找到一种方法来远程登录到未root的机器人 我有INTERNET权限处于活动状态 我的设备与我的设备连接在同一网络上Mac OS X通过 WiFi 我可以 ping 通我打开的端口 在最初的实验中 我让它在有根测试设备上工作 但我
  • 确定方法调用顺序的接口设计模式

    我想创建一个具有多种方法的 Java 接口 但我希望界面的用户只能按照我定义的顺序或顺序调用方法 例如buyTicket 不应在此之前调用reserveTicket 问 有没有设计模式或任何关于如何做到这一点的提示 我考虑过 A 接口被包装
  • Android Studio同时为同一个项目构建两个应用程序

    我正在使用 Android Studio v0 5 9 制作一个应用程序 它有一个图书馆项目作为依赖 但是 每次我运行该项目时 都会将两个具有相同名称和图标的 APK 部署到我的设备上 第一个 apk app 包含我的主模块 而第二个是库项
  • 改造中的 SocketTimeoutException

    我在尝试着POST向服务器请求获取数据但有时会发生SocketTimeoutException I used Ok3Client解决它 但我面临同样的异常 我该如何解决它 我的代码如下 public void getNormalLogin
  • ContactsContract.CommonDataKinds.Phone.CONTENT_URI 与 ContactsContract.Contacts.CONTENT_URI

    In 如何在android中检索联系人列表 https stackoverflow com questions 16124034 how to retrieve the list of contacts in android我看到代码允许您
  • 找不到 com.google.gms:google-services:4.1.0 [重复]

    这个问题在这里已经有答案了 Bitrise 构建失败并出现以下错误 配置根项目 src 时出现问题 无法解析配置 classpath 的所有文件 找不到 com google gms google services 4 1 0 在以下位置进

随机推荐