小编Ism*_*sco的帖子

某些设备无法接收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);

}
Run Code Online (Sandbox Code Playgroud)

目前它只发生在一个带有android 6.0.1的root设备中希望你可以帮助我:)

编辑:我发送的通知HTTP请求:

"to": …
Run Code Online (Sandbox Code Playgroud)

android firebase firebase-cloud-messaging firebase-notifications

11
推荐指数
1
解决办法
3184
查看次数