Некоторые устройства не получают уведомления FCM
У меня проблема, так как некоторые из моих устройств, на которых я тестирую свое приложение, не получают их уведомлений и не создают исключения.
Уведомления поступают из FCM, и я использую настраиваемую службу, чтобы показать их.
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);
}
В настоящий момент это происходит только в корневом устройстве с android 6.0.1
Надеюсь, ты сможешь мне помочь:)
EDIT:
Запрос HTTP-запроса уведомления:
"to": "/topics/general",
"notification" : {
"title": "title",
"body": "body",
},
"data": {
"tipo": "normal",
}
Ответы
Ответ 1
Одной из возможных причин этого может быть то, что некоторые из устройств, на которых вы тестируете, не имеют сервисов Google Play или обновленной версии. В своей деятельности попробуйте проверить сервисы Google Play. Вы можете использовать функцию в качестве ответа здесь:
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;
}
Ответ 2
это случается иногда на устройствах с низким уровнем. Одним из решений является очистка данных приложения и кеша приложения Google Play Services. Эта работа для меня.
Ответ 3
Я не знаю, работает ли это, но ваше сырое тело JSON ошибочно. Вы забыли {}
снаружи как объект JSON. Ниже должно быть отправлено ваше сообщение.
{
"to": "/topics/general",
"notification" : {
"title": "title",
"body": "body",
},
"data": {
"tipo": "normal",
}
}