firebase subscribeToTopic OnCompleteListener is not getting called

北城余情 提交于 2019-12-24 18:33:50

问题


I am working on an android project in which user will subscribe to a Firebase topic. I have written code like below.

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");
                    }
                }
            });

But the problem is the onComplete method in the code is not at all called. It is not even showing the failure case. What could be the problem? Since the user is not subscribed to the topic, I am not able to send push notifications. Here are more details...

Manifest file: I have added in the application tag of manifest file.

    <service
        android:name=".MyFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT"/>
        </intent-filter>
    </service>

Gradle App :

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 project:

  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'
   }
 }

EDIT:

I have checked the subscription of the topic like below, using postman

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"
}

The above result does not show any topics.

来源:https://stackoverflow.com/questions/51990463/firebase-messages-are-not-receiving

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!