Android app not receiving firebase notification

android firebase firebase-notifications

554 观看

3回复

4659 作者的声誉

My android app is not receiving any firebase notification. When I send a message from the firebase console it is showing that the process is completed and when the row is expanded it shows 0 message send, screenshot below

Screenshot

Expiry of the message is set to 1 minute.

I've added the FirebaseMessagingService , FirebaseInstanceIdService and added the services in the manifest like this

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

I've tried adding

android:enabled="true"
android:exported="true"

This is the onCreate method of application class

@Override
public void onCreate() {
    super.onCreate();
    mGlide = Glide.with(this);

    String token = FirebaseInstanceId.getInstance().getToken();
    if (token != null)
        M.log("Firebase Token", token);
}

and I've a valid token in the logcat output

I did everything they said the documentation, but it is not working. Did I miss something important?

作者: Sony 的来源 发布者: 2017 年 9 月 15 日

回应 3


0

1169 作者的声誉

have you put google-services.json in your app folder ? . if not please put it in app folder and look information in this file it is relavant to your project or not . Try to send notification by selecting your application package name . I hope this will work. Thanks

作者: chandrakant sharma 发布者: 2017 年 9 月 15 日

0

0 作者的声誉

Make sure that your app is not running when you are sending the notification. If your app is in the foreground then you won't be able to receive notifications.

If you want to receive notifications when your app is in foreground, edit your service as follow:

public class TjssFireBaseMessagingService extends FirebaseMessagingService {

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    if (remoteMessage.getNotification() != null) {
        Intent i = new Intent(getApplicationContext(), MainActivity.class);
        i.putExtra("Val", remoteMessage.getNotification().getTitle());
        startActivity(i);
    }
}

@Override
public void onDeletedMessages() {
    super.onDeletedMessages();
}}

The above code will start your main activity when a notification is received and your app is in foreground.

作者: user8583580 发布者: 2017 年 9 月 15 日

1

527 作者的声誉

In your onCreate of Application add this

FirebaseApp.initializeApp(this);

this meaning context here

作者: Rishabh Dugar 发布者: 2017 年 9 月 15 日
32x32