首页 > 解决方案 > com.parse.fcm.ParseFirebaseInstanceIdService' 不可分配给 'android.app.Service'

问题描述

首先,我查看了这篇文章和这篇文章,提出了类似的问题,但它们似乎都没有解决我遇到的问题。

我想做什么?

我正在使用 Parse 服务器将应用程序从 Google Cloud Messaging 升级到 Firebase Cloud Messaging。有几个关于这个的教程(我正在使用这个),都指定您需要在清单中添加以下行:

<service
    android:name="com.parse.fcm.ParseFirebaseInstanceIdService"
    android:exported="true">
    <intent-filter>
        <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
    </intent-filter>
</service>

出了什么问题?

但是,如果这样做,我会收到错误com.parse.fcm.ParseFirebaseInstanceIdService' is not assignable to 'android.app.Service。我似乎找不到任何关于如何解决这个问题的资源,或者这是否是接收任何消息的问题。

我的项目 gradle 文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        mavenCentral()
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.2'
        classpath 'com.google.gms:google-services:4.3.3'  // Google Services plugin
    }
}
allprojects {
    repositories {
        google()
    }
}

还有我的模块 gradle 文件:


android {
    compileSdkVersion 28
    lintOptions {
        abortOnError false
    }

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 28
        multiDexEnabled true
    }

    testOptions {
        unitTests.returnDefaultValues = true
    }
}

buildscript {
    repositories {
        mavenCentral()
        google()
    }
}

repositories {
    mavenCentral()
    google()
    jcenter()
    maven {
        url "https://s3.amazonaws.com/repo.commonsware.com"
    }
    maven {
        url 'https://jitpack.io'
    }
    maven {
        url 'https://maven.google.com/'
        name 'Google'
    }
    maven {
        url 'https://jitpack.io'
    }
    google()
}

dependencies {
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.multidex:multidex:2.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.code.gson:gson:2.8.1'
    implementation 'com.mcxiaoke.volley:library:1.0.19'
    implementation 'com.parse:parse-android:1.17.3'
    implementation 'com.parse:parse-fcm-android:1.17.3' // Firebase cloud messaging
    implementation 'com.google.firebase:firebase-core:17.2.1'
    implementation 'com.google.firebase:firebase-messaging:20.0.1'
    implementation 'com.github.mtotschnig:stickylistheaders:2.7.1'
    testImplementation 'junit:junit:4.12'
    testImplementation 'org.mockito:mockito-core:1.10.19'
}

apply plugin: 'com.google.gms.google-services' // Google Play services Gradle plugin 

任何想法出了什么问题以及如何解决它?

标签: androidparse-platformfirebase-cloud-messagingandroid-manifest

解决方案


Md. Asaduzzaman 的回答很有帮助,谢谢。

只是要添加到它,请确保覆盖自定义 FirebaseMessagingService 中的 onNewToken() 方法,就像在教程中一样。(我刚刚找到了教程,并认为如果其他人遇到同样的问题,分享它会很好)。

@Override
public void onNewToken(String s) {
    super.onNewToken(s);
    Log.e("NEW_TOKEN",s);
}

我们需要覆盖它,因为:

“类 FirebaseInstanceIdService:此类已被弃用。赞成在 FirebaseMessagingService 中覆盖 onNewToken。

一旦实施,就可以安全地删除这项服务。”


推荐阅读