1

FCM Push Notification not working when app close in some of the devices like xiaomi, oppo, vivo,Redmi and some of OS (Oxygen OS, Color OS, MIUI etc).

But other devices and OS working good.

Does anyone have experience about it?

Android end code.

public class MyFirebaseMessagingService extends FirebaseMessagingService {

private static final String TAG = "MyFirebaseMsgService";

/**
 * Called when message is received.
 *
 * @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
 */
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    Log.e(TAG, "From: " + remoteMessage.getFrom());


}

}

public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {

private static final String TAG = MyFirebaseInstanceIDService.class.getName();

@Override
public void onTokenRefresh() {
    // Get updated InstanceID token.
    String refreshedToken = FirebaseInstanceId.getInstance().getToken();
    Log.d(TAG, "Refreshed token: " + refreshedToken);

    // If you want to send messages to this application instance or
    // manage this apps subscriptions on the server side, send the
    // Instance ID token to your app server.
    sendRegistrationToServer(refreshedToken);
}

private void sendRegistrationToServer(String refreshedToken) {


}

}

<service
        android:name=".MyFirebaseInstanceIDService"
        android:stopWithTask="false"
        >
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
        </intent-filter>
    </service>

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

Sever End Code

{
"notification": {
"title": "FCM Kazi",
"body": "FCM bdoy1 ",
"sound": "default",
"click_action": "FCM_PLUGIN_ACTIVITY",
"icon": "fcm_push_icon"
},
"data": {
"param1": "value1",
"param2": "value2"
},
"to": "cVL4I6upF-g:APA91bE7EFv3apIMHuEL_oCoVvhhrUw-ftM6S11RE9HOF58wf3ewYkDUh9wUhUCMIa6zoftOgGH5HWt0rPKVHw2OShn06tIESFnGo9u8rooJ9qfiXQQlg-zZzjgi0cQ64BUaZnUCM09R",
"priority": "high"
}
Community
  • 1
  • 1
user3742866
  • 136
  • 6
  • Check this answer it will work https://stackoverflow.com/questions/51123197/firebaseinstanceidservice-is-deprecated/51129304#51129304 – AskNilesh Oct 10 '18 at 09:21
  • I read a much and when i removed "notification" block, it worked in background and foreground properly. But you need to add "title" and "body" to "data" block. https://stackoverflow.com/a/37845174/6055194 https://stackoverflow.com/a/38795553/6055194 – Eugene Babich Oct 10 '18 at 09:25
  • Thanks @ZhebzhikBabich but not working some of the devices like xiaomi oppo, vivo,Redmi and some of OS (Oxygen OS, Color OS, MIUI etc). this problme only Color OS, – user3742866 Oct 10 '18 at 10:14
  • Did you try to change yout version of firebase messaging to 17.3.x (1,2,3) and remove FirebaseMessagingService? – Eugene Babich Oct 10 '18 at 10:32
  • Yes. @ZhebzhikBabich implementation 'com.google.firebase:firebase-messaging:17.3.3' – user3742866 Oct 10 '18 at 10:37
  • That's really serious bug. Minus to Google – Eugene Babich Oct 10 '18 at 10:38
  • i am checked redmi is working fine. are u give correct to-address id(token) otherwise use firebase console https://console.firebase.google.com/project/fcmsample-a38c3/notification/compose. choose new message and select usersegment and app package select as send message it received install all devices – Bhuvaneshwaran Vellingiri Oct 10 '18 at 11:22
  • @BhuvaneshwaranVellingiri { "multicast_id": 6495072320217040420, "success": 1, "failure": 0, "canonical_ids": 0, "results": [ { "message_id": "0:1539170495316171%c6c2f7c7c6c2f7c7" } ] } FCM Return "success": 1, It working when FCM are working on foreground and background but not kill status. – user3742866 Oct 10 '18 at 11:27
  • @BhuvaneshwaranVellingiri, I am testing on oppo android 6 colorOS. – user3742866 Oct 10 '18 at 11:28

1 Answers1

-1

Use only data playload and remove notification playload. Data playload always receive wheather app is open or close doesn't matter. Notification playload works only if app is in forground. And if you are not receiving on few devices go to device settings and enable receive notification for that app. Few manufacturer doesn't allow notification by default.