我正在开发一个Android项目,用户将在其中订阅Firebase主题。我已经写了如下代码。
FirebaseMessaging.getInstance().subscribeToTopic("update")
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (!task.isSuccessful()) {
Log.d("SUBSCRIPTION","FAILURE");
}else{
Log.d("SUBSCRIPTION","SUCCESS");
}
}
});
但是问题是代码中的onComplete方法根本没有被调用。它甚至没有显示故障情况。可能是什么问题呢?由于用户尚未订阅该主题,因此我无法发送推送通知。这里有更多详细信息...
清单文件:我已经在清单文件的应用程序标签中添加了
。 <service
android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
Gradle应用:
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-crash:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.3.0'
}
apply plugin: 'com.google.gms.google-services'
Gradle项目:
buildscript {
repositories {
jcenter()
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.0.1'
}
}
编辑:
我已经使用邮递员检查了如下主题的订阅
https://iid.googleapis.com/iid/info/xxxxxxxxxxxxxxxxx_V7dnQnfaT7f8cV-aNdDqrqyIJdI-fbnai0ec1Dyjm0uoJS0i1mxMfemE0iObR0j0f4mN_4Jyn-vSY4BTxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx?details=true
Authorization: key=xxxxxx //server key
method: GET
RESULT:
{
"applicationVersion": "109",
"connectDate": "2018-08-23",
"attestStatus": "NOT_ROOTED",
"application": "in.xxx.xxxxxxx",
"scope": "*",
"authorizedEntity": "45xxxxxxxxx8",
"connectionType": "MOBILE",
"appSigner": "e9a7xxxxxxxxx29fa0105d0xxxxxxxx33cc",
"platform": "ANDROID"
}
以上结果未显示任何主题。