来自Firebase控制台的通知发送失败,但向所有设备发送的状态标记为已完成。

7

我已经使用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


你必须重写onMessageReceived方法吗?我以为Firebase Messaging会显示默认通知。 - Numan Karaaslan
没有默认通知。 - Zaeem Sattar
2个回答

4

您的发送者 ID 不匹配,或者您在应用程序中输入了错误的项目 ID。


是的,实际上我两个都输入错误了,但现在问题已经解决了。谢谢。 - Zaeem Sattar
你能告诉我你是怎么解决这个问题的吗?我已经卡了三天了。@zaeemsattar - Pratik Dasa

1

从日志来看,我认为您正在通过注册ID向特定设备发送消息,但我们发现发送者ID不匹配的错误。请确保这些注册ID有效,并适用于正确的应用程序。


是的,谢谢。我刚刚弄明白了,我使用了错误的发送者ID。 - Zaeem Sattar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接