12

I'm having a problem since some of my devices where I'm testing my app don't receive their notifications and it doesn't raise an exception.

The notifications comes from FCM and I'm using a custom service to show them.

MyFirebaseMessaginService.java

static int count = 0;
@Override
public void onMessageReceived(final RemoteMessage remoteMessage) {

    Log.i("remoteMessage",remoteMessage.toString());
    switch(remoteMessage.getData().get("tipo")){
        case "normal":
            notificacionNormal(remoteMessage);
            break;
        case "imagen":
            notificacionImagen(remoteMessage);
            break;
        case "imagen+url":
            notificacionImagenUrl(remoteMessage);
            break;
    }
    count++;
    //Log.d("prueba",remoteMessage.getData().get("imagen"));
}

private void notificacionImagenUrl(RemoteMessage remoteMessage) {
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse(remoteMessage.getData().get("url")));
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 100, i, PendingIntent.FLAG_ONE_SHOT);

    NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notif = new Notification.Builder(this)
            .setContentIntent(pendingIntent)
            .setContentTitle(remoteMessage.getNotification().getTitle())
            .setContentText(remoteMessage.getNotification().getBody())
            .setSmallIcon(R.mipmap.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
            .setStyle(new Notification.BigPictureStyle().bigPicture(getImagae(remoteMessage.getData().get("imagen"))))
            .build();
    notif.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(count, notif);

}

At the moment it only happens in a rooted device with android 6.0.1 Hope u can help me :)

EDIT: The notification HTTP request I send:

"to": "/topics/general",
        "notification" : {
          "title": "title",
          "body": "body",
        },
        "data": {
          "tipo": "normal",
        }
mhatch
  • 4,441
  • 6
  • 36
  • 62
Ismael Blasco
  • 161
  • 2
  • 7
  • Can you post your sample payload? Also, is this happening only to some specific devices or its random on all of your test devices? – AL. Jun 08 '16 at 23:06
  • @intj its only happening on one testing device and he isnt getting anithing ( it didnt even reach the first log ), and the play services are installed on the device. Wath do you mean with a playload? – Ismael Blasco Jun 09 '16 at 00:11
  • Are you sure that the `registrationToken` corresponding to that device is a recipient? I was referring to the notification payload. Or are you sending notifications thru the Firebase console? – AL. Jun 09 '16 at 00:20
  • Im sending them with topics and i tried to from the console and still do nothing, i will edit now with the http petition – Ismael Blasco Jun 09 '16 at 00:28
  • Did you verify if that that specific device is subscribed to the topic you are sending it to? – AL. Jun 09 '16 at 04:11
  • @intj YEs i tried sending a global notification and still nothing – Ismael Blasco Jun 09 '16 at 11:16
  • That's strange.. Is that specific device the only rooted device? Or are there any other devices rooted (which still receives the notification)? – AL. Jun 09 '16 at 23:39
  • @intj it isnt the only routed device i tested it, and they get the notification – Ismael Blasco Jun 10 '16 at 00:39
  • Did you add the MyFirebaseMessaginService in the AndroidManifest.xml ? – Diego Giorgini Jun 10 '16 at 04:02
  • @DiegoGiorgini Yes. It works on other devices – Ismael Blasco Jun 10 '16 at 13:53
  • Hey did you find any answer – Pritish Joshi Jul 27 '16 at 06:55
  • @DevQualwebs sorry but no, it started working alone around a week on the phone but i dont know why it happens. – Ismael Blasco Jul 28 '16 at 07:42
  • 2
    Is your phone an ASUS or a Mi device? Some of those devices has an app called Auto-start Manager which prevents other apps from receiving notifications. You could enable notifications from there. – gerardnimo Jul 31 '16 at 17:05
  • i just want to tell you, same thing is happening with my live app. firebase response shows successful delivered but end user didn't get any notification. if you find any solution please tell me too. – Kamal Bunkar Jan 20 '17 at 18:21
  • I am also facing same problem. I can receive notification in Moto but I didn't get in Asus Mobile.Let us know if u find solution for this issue – Gopal Mar 27 '17 at 17:11

3 Answers3

1

One of the possible reasons for this might be that some of the devices on which you're testing don't have google play services or the updated version of it. In your activity, try checking for google play services. You may use the function as answered here:

protected boolean checkPlayServices() {
final int resultCode = 

GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity());
    if (resultCode != ConnectionResult.SUCCESS) {
        if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, activity(),
                    PLAY_SERVICES_RESOLUTION_REQUEST);
            if (dialog != null) {
                dialog.show();
                dialog.setOnDismissListener(new OnDismissListener() {
                    public void onDismiss(DialogInterface dialog) {
                        if (ConnectionResult.SERVICE_INVALID == resultCode) activity().finish();
                    }
                });
                return false;
            }
        }
        new CSAlertDialog(this).show("Google Play Services Error",
                "This device is not supported for required Goole Play Services", "OK", new Call() {
                    public void onCall(Object value) {
                        activity().finish();
                    }
                });
        return false;
    }
    return true;
}
Community
  • 1
  • 1
Pinaki Acharya
  • 339
  • 3
  • 11
0

it happens sometimes on low end devices. One solution is to clear the app data and cache of Google Play Services App. This work for me.

Ramiz Ansari
  • 524
  • 1
  • 6
  • 16
0

I don't know if this works, but your raw JSON body is wrong. You forgot the {} outside as a JSON object. Below should be your message to be sent.

{
    "to": "/topics/general",
    "notification" : {
        "title": "title",
        "body": "body",
    },
    "data": {
        "tipo": "normal",
    }
}
Pang
  • 9,564
  • 146
  • 81
  • 122
Sarith Nob
  • 337
  • 2
  • 13