3

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.

Naroju
  • 2,637
  • 4
  • 25
  • 44
  • 1
    First: Are you sure the device isn't being subscribed? It might be happening, and you're just not getting a callback. Second: I've seen another question here asking the same thing. It might be a bug. Please file a bug report with your observations. https://firebase.google.com/support/contact/bugs-features/ – Doug Stevenson Aug 23 '18 at 17:56
  • Did you test this using an emulator or a physical device? Have you tried on multiple devices? If you revert to an older version of the FCM library, does it work? Basing on the post so far, there isn't anything we could pinpoint other than this could possibly be a bug. – AL. Aug 23 '18 at 17:57
  • @DougStevenson. I have edited question how I checked its subscription. The question you are asking about may be mine https://stackoverflow.com/questions/51990463/firebase-messages-are-not-receiving. After asking that question, I figured that topic is not getting subscribed – Naroju Aug 23 '18 at 18:05
  • @AL. I am using a physical device. – Naroju Aug 23 '18 at 18:06
  • @AL. It is working fine if I use the older version which is 11.0.0. But it is a very old version. – Naroju Aug 23 '18 at 19:10
  • please don't get me wrong.. @DougStevenson. Does firebase has anything to do with this line . I just removed this line from manifest. Now it is working for newer versions too. – Naroju Aug 23 '18 at 19:24
  • Did you find the solution for this issue @Naroju? – Kavin Raju S Jun 02 '20 at 11:24
  • 1
    Its almost two years, I found the problem came due to the wake lock permission that i had added. I removed it and worked fine. – Naroju Jun 02 '20 at 16:27

0 Answers0