com.parse.fcm.ParseFirebaseInstanceIdService' 不可分配给 'android.app.Service'
com.parse.fcm.ParseFirebaseInstanceIdService' is not assignable to 'android.app.Service'
首先,我查看了 this post and this post,提出了类似的问题,但它们似乎都没有解决我遇到的问题。
我想做什么?
我正在使用 Parse 服务器将应用程序从 Google 云消息传递升级到 Firebase 云消息传递。有几个教程(我正在使用 this one),都指定您需要在清单中添加以下行:
<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
知道哪里出了问题以及如何解决吗?
医学博士。 Asaduzzaman 的回答很有帮助,谢谢。
只需添加,请确保覆盖自定义 FirebaseMessagingService 中的 onNewToken() 方法,就像 this 教程中那样。 (我刚刚找到教程,我认为如果其他人遇到同样的问题,分享它会很好)。
@Override
public void onNewToken(String s) {
super.onNewToken(s);
Log.e("NEW_TOKEN",s);
}
我们需要覆盖它,因为:
"Class FirebaseInstanceIdService:
此 class 已弃用。
赞成覆盖 FirebaseMessagingService 中的 onNewToken。
实施后,可以安全地删除此服务。"
首先,我查看了 this post and this post,提出了类似的问题,但它们似乎都没有解决我遇到的问题。
我想做什么?
我正在使用 Parse 服务器将应用程序从 Google 云消息传递升级到 Firebase 云消息传递。有几个教程(我正在使用 this one),都指定您需要在清单中添加以下行:
<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
知道哪里出了问题以及如何解决吗?
医学博士。 Asaduzzaman 的回答很有帮助,谢谢。
只需添加,请确保覆盖自定义 FirebaseMessagingService 中的 onNewToken() 方法,就像 this 教程中那样。 (我刚刚找到教程,我认为如果其他人遇到同样的问题,分享它会很好)。
@Override
public void onNewToken(String s) {
super.onNewToken(s);
Log.e("NEW_TOKEN",s);
}
我们需要覆盖它,因为:
"Class FirebaseInstanceIdService: 此 class 已弃用。 赞成覆盖 FirebaseMessagingService 中的 onNewToken。
实施后,可以安全地删除此服务。"