0

I am working on an android project for which I am using Firebase cloud messaging to send some push notifications. Messages used to deliver correctly. I wanted to update the app with the latest firebase API. After doing that, I don't know what happened now cloud messages are not delivering at all. when app opened user gets subscribed to a topic called "update". 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");
                        Toast.makeText(getApplicationContext(),"FAILURE",Toast.LENGTH_SHORT).show();
                    }else{
                        Log.d("SUBSCRIPTION","SUCCESS");
                        Toast.makeText(getApplicationContext(),"SUCCESS",Toast.LENGTH_SHORT).show();

                    }
                }
            });

I have written this code in the First activity's onCreate method. I have also observed that the addOnCompletelistener in the above code is not at all getting called.

Android side code:

public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {


    Log.d("FROM", "From: " + remoteMessage.getFrom());

    Log.d("DATA", "Message data payload: " + remoteMessage.getData());

}


@Override
public void onNewToken(String s) {
    super.onNewToken(s);
    Log.d("TAG", "Refreshed token: " + s);
}
}

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

I am using postman to send push notifications:

https://fcm.googleapis.com/fcm/send
Authorization: key=xxxxxxxxxxxxx // server key
METHOD: POST
{
  "to":"/topics/xxxx",
  "collapse_key" : "xxxxxxxx",
  "data" : {
    "versioncode":107
  }
}
Naroju
  • 2,637
  • 4
  • 25
  • 44
  • This Question is Duplicate of [Firebase cloud messaging notification not received by device](https://stackoverflow.com/q/37351354/7734566) – 5ec20ab0 Aug 23 '18 at 16:41
  • I saw that post. Did not help me – Naroju Aug 23 '18 at 16:42
  • I solved it. I needed to remove from my manifest file. Then it worked. I don't understand what is the relation between Firebase and wake lock really. May be this helps https://stackoverflow.com/questions/48255090/firebase-and-wake-locks-issue-in-android – Naroju Aug 23 '18 at 19:27
  • Please don't repeat questions. Simply editing this post with any new information you had, or any new code you'd tried, would've bumped it to the top of the active queue. I've closed this as a duplicate of the newer one, since you're getting assistance from Doug there, but, in the future, please just edit the original. – Mike M. Aug 24 '18 at 07:08

0 Answers0