2017-02-27 6 views
0

내 응용 프로그램에 알림을 보내고 알림을 클릭하면 다른 활동이 whatsapp 알림과 같이 열리길 원합니다.
이것은 내 코드 C입니다. 누구의 도움 ?????알림을 클릭 한 후 특정 활동을 수행 할 수있는 방법

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()); 

     } 

답변

0

유형을 식별하기 위해 메시지 내용에 추가 매개 변수를 추가해야합니다. 그런 다음 해당 유형 값을 기반으로 다른 활동으로 통지 관리자를 작성하십시오.

예 :

switch (type){ 
case 1: 

notification manager for activity A 

break: 

case 2: 

notification manager for activity B 

break: 

} 
관련 문제