2017-02-27 3 views
0

Ich möchte meine Anwendung sollte mir eine Benachrichtigung geben und beim Klicken auf die Benachrichtigung sollte eine andere Aktivität wie WhatsApp Benachrichtigungen öffnen
das ist mein Code c any help ?????Wie kann ich auf bestimmte Aktivität nach dem Klicken auf die Benachrichtigung weitergehen

public class MyFirebaseMessagingService extends FirebaseMessagingService { 
     @Override 
     public void onMessageReceived(RemoteMessage remoteMessage) { 
      // sendNotification(remoteMessage.getNotification().getBody()); 
      //Bundle bundle=new Bundle(); 
      //bundle.putString("msgBody",remoteMessage.getNotification().getBody()); 
      //intent use for start this activity after click on notification 
      Intent intent = new Intent(getApplicationContext(),Secondactivity.class); 
      String valu=remoteMessage.getNotification().getBody(); 
      intent.putExtra("notificationmessage",valu); 
**strong text**   //here we are telling system after clicking you have to come on mainactivity 
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
      //here we are giving rights to main activity.FLAG_ONE_SHOT useful to indicate this pending intent can use only once 
      PendingIntent pendingintent=PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT); 
      //notificationcompat useful for creating notification layout 
      NotificationCompat.Builder notificationbuilder=new NotificationCompat.Builder(this); 
      notificationbuilder.setContentText(remoteMessage.getNotification().getBody()); 
      notificationbuilder.setContentTitle("FCM NOTIFICATION"); 
      notificationbuilder.setSmallIcon(R.mipmap.ic_launcher); 
      notificationbuilder.setAutoCancel(true); 
      notificationbuilder.setContentIntent(pendingintent); 

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

     } 

Antwort

0

Sie haben einen zusätzlichen Parameter in dem Nachrichteninhalt hinzufügen, um die Art zu identifizieren. Erstellen Sie dann basierend auf diesem Typwert einen Benachrichtigungsmanager mit unterschiedlichen Aktivitäten.

ex:

switch (type){ 
case 1: 

notification manager for activity A 

break: 

case 2: 

notification manager for activity B 

break: 

} 
Verwandte Themen