android - 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
任何想法出了什么问题以及如何解决它?
解决方案
Md. Asaduzzaman 的回答很有帮助,谢谢。
只是要添加到它,请确保覆盖自定义 FirebaseMessagingService 中的 onNewToken() 方法,就像在本教程中一样。(我刚刚找到了教程,并认为如果其他人遇到同样的问题,分享它会很好)。
@Override
public void onNewToken(String s) {
super.onNewToken(s);
Log.e("NEW_TOKEN",s);
}
我们需要覆盖它,因为:
“类 FirebaseInstanceIdService:此类已被弃用。赞成在 FirebaseMessagingService 中覆盖 onNewToken。
一旦实施,就可以安全地删除这项服务。”
推荐阅读
- symfony - 使用 cleanupOutputBeforeBuild 保留符号链接 Encore
- java - 使用java运行nodejs
- git - git 可以只具体显示哪些提交被合并到 master 中吗?
- python - 如何使用 Python opencv 以 100% 缩放显示非常小的图像
- apache-zeppelin - 如何在 Zeppelin 中基于 HadoopGroupProvider 中的组配置角色,使用 Knox 提供基于 SAML 的 SSO?
- javascript - 如何在url地址中用参数#重定向,我用的是laravel 5.8
- visual-studio-code - 如何在vscode中减少xml中选择的缩进
- c++ - Qt没有这样的方法槽
- identity - 什么是创建随机单词序列以制作易于指示的标识符的好方法?
- javascript - 如何在fabric js中的canvas.toJSON()中不修剪两个小数点的情况下获得比例的原始值?