android - 通知从 firebase 控制台发送但显示失败状态但发送到所有设备被标记为已完成

标签 android firebase firebase-notifications

我已经通过 firebase 实现了推送。

我正在发送通知,但收到“失败”状态。当我向所有设备发送通知时,它被标记为已完成,但我仍然没有在设备中收到消息。

即使我向单个设备发送消息,它也会显示失败并且不会在设备上收到通知。

代码是

private static final String TAG = "StartingAndroid";

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    //It is optional
    Log.e(TAG, "From: " + remoteMessage.getFrom());
    Log.e(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());

    //Calling method to generate notification
    sendNotification(remoteMessage.getNotification().getTitle(),remoteMessage.getNotification().getBody());
}

//This method is only generating push notification
private void sendNotification(String title, String messageBody) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle(title)
            .setContentText(messageBody)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0, notificationBuilder.build());
}

here is console

最佳答案

您的发件人 ID 不匹配,或者您在申请中输入了错误的项目 ID。

关于android - 通知从 firebase 控制台发送但显示失败状态但发送到所有设备被标记为已完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38002951/

相关文章:

android - "MapFragment cannot be resolved to a type"即使我在 API 级别 17

Android - 如何从相机或画廊拍照

Node.js/Express 本地磁盘缓存

javascript - Firebase 部署在 Node js 上

android - 创建 FCM 主题需要很长时间才能在控制台中显示

android - 无法使用 Pubnub 教程解析方法 requestLocationUpdates

java - 如何区分不同的wifi网络?

Android Firebase DataSnapshot 类向自定义 java 对象返回 null

javascript - Chrome 和 Firefox 不记得用户 session

ios - swift 3,ios 10 - 未收到推送通知 firebase