については
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// TODO(developer): Handle FCM messages here.
Log.d(TAG, "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated. See sendNotification method below.
}
によるFirebase通知ハンドル、あなたが言及しました。使用可能なフラグのために、このリンクを参照してください:https://developer.android.com/reference/android/content/Intent.html
その後、あなたはこのように、これらのフラグを使用することができ、活動を開始するときに
Intent intent = new Intent(context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
。
リストに記載されている3つ目の問題については、クリックした後に発生する通知に保留中のインテントを割り当てることができます。
Intent intent = new Intent(this, FNotiReceiver.class);
intent.setAction("com.nepal.application.pendingIntent");
intent.putExtra("Name", "Data/Value");
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, notification_ID,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
、あなたが使用することができ、それをクリックした後、通知を削除するには:
NotificationManager notifManager= (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notifManager.cancel(notification_ID);
申し訳ありませんが、私はあなたの第一の問題に正確な答えを持っていないが、私はバックグラウンドサービスを作成することが助けになると思います。
私にも同じ問題があります。私はユーザーがクリックするのを待たずに通知データを取得できません(アクティビティが開いている場合)。 – user392117
アプリがバックグラウンドで*の*通知*メッセージを受信した場合、そのメッセージはアプリに配信されません。 Firebaseは通知トレイにメッセージを表示します。通知トレイをクリックすると、アプリが起動します。 http://stackoverflow.com/questions/37809885/firebase-push-notifications-update-db/37843845#37843845を参照してください。 –