私はAndroidベースのアプリケーションにFirebase Cloud Messagingを使用しています。前回のプッシュ通知にGCMBaseIntentServiceを使用していました。 Firebase Cloud Messagingが見つかりました.FirebaseMessagingServiceはGCMBaseIntentService()と異なります。 GCMBaseIntentServiceの場合、アプリケーションがプッシュ通知を受信すると、onMessage()関数が常に呼び出されます。プッシュ通知をクリックすると、受信したデータを操作して特定のページに移動できます。Firebase Cloud Messaging:通知をプッシュしてアプリケーションの特定のページに移動します
しかし、FirebaseMessagingServiceのonMessageReceived()が呼び出されていないことに気付きました。プッシュ通知を受け取ったときに、特定のアプリケーションにどのようにナビゲートすることができるのか分かりますか?問題は、プッシュ通知の内容に基づいてアプリケーション内の別のページに移動する必要があることです。
次は代わりに通知のデータメッセージを使用し
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
sendNotification(remoteMessage.getNotification().getBody());
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
}
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, HomeControllerActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_ic_notification)
.setContentTitle("FCM Message")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
主な問題は、onMessageReceived()関数がまったく呼び出されていないことです。アンドロイドスタジオの私のlogcatは、私のログメッセージをonMessageReceived()関数に表示しません。それ以外の方法で私がPushNotiticationの特定のコンテンツを入手して、アプリケーション –
の特定のページに移動できるようにしてください。https://firebase.google.com/docs/cloud-messaging/concept-options – Anil
通知メッセージを送信しています – Anil