1

Firebaseについて学びました。そして私はそれから正常に通知を受けました。しかし、通知をクリックすると、別のアクティビティをどのように開くことができますか?Firebase Androidからのハンドル通知

この私のコード:通知に関する

public class MyFirebaseMessagingService extends FirebaseMessagingService { 

private static final String TAG = "MyFirebaseMsgService"; 

@Override 
public void onMessageReceived(RemoteMessage remoteMessage) { 
    super.onMessageReceived(remoteMessage); 
    Log.d("msg", "onMessageReceived: " + remoteMessage.getData().get("message")); 
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this) 
      .setSmallIcon(R.mipmap.ic_launcher) 
      .setContentTitle("test") 
      .setContentText(remoteMessage.getData().get("message")); 
    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    manager.notify(0, builder.build()); 



} 
+0

Firebaseコンソールから通知を送信していますか?データメッセージを使用する必要があります –

+0

[ファイアベースのFCM通知を\ _アクションペイロード](http://stackoverflow.com/questions/37407366/firebase-fcm-notifications-click-action-payload)の可能な重複の可能性がありますように私は –

+0

ここに解決策を見つける –

答えて

0

を定義する必要がありますあなたのペイロードをdataキーに入れます

+0

あなたに働いていただきありがとうございます –

0

イッツSTH、何もfirebaseを行います。

check thisはあなたが必要とする、Tosinが示唆したように、あなたがFirebaseコンソールからプッシュ通知を送信している場合は、NotificationManager

Intent intent = new Intent(this, MyActivity.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.drawable.your_icon) 
     .setContentTitle("Notification Title") 
     .setContentText(messageBody) 
     .setAutoCancel(true) 
     .setContentIntent(pendingIntent); 

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
notificationManager.notify(0, notificationBuilder.build()); 

をPendingIntentを構築し、使用して通知する必要がある通知のアクション

関連する問題