1

I이 4 층/스택, 같은 뭔가가있는 앱안드로이드 알림, 부하 하나 이상의 통지

홈페이지 >> DetailPage >> MapPage >> ChatPage

가 최신 의도

나는 C를 것, 다른 대화를위한

(ChatId 말, 각 대화는 고유의 ID를 가지고 있습니다) 나는 다른 채팅 메시지를 수신 할 때마다 알림을 만들 수 관리 requestCode가 내가 직면하고 문제는 내가 1 개 이상 통지를받은 때마다, ChatId1ChatId2 다음, 먼저 말을한다는 것이다 pendingIntent

에서로 ChatId를 사용하여 알림을 reate. 의 대화 ChatId2 내가 ChatId1의 알림을 클릭하면 다음에,이 ChatPage에로드 대화를하고, ChatId2 수있는 최신 의도를 시작합니다입니다.

질문은 내가 내가 ChatId1의 알림을 클릭하면, 그래서, 그것은 ChatId1의 메시지를로드하게하고, 클릭이 ChatId2에, 그것은 의 메시지 ChatId2를로드 할 때 할 수있는 방법이다.

다음은 당신이 고유 할 각 사용자의 의도에 대한

intent.setAction(Long.toString(System.currentTimeMillis())); 

사용

내 알림

public void createLocalNotification(String meetingIdLong, String countryCode, String phoneNumber, String contactName, String chatMessage) { 

      // Prepare intent which is triggered if the 
      // notification is selected 
      Intent intent = new Intent(this, ChatLog.class); 
      long L = Long.parseLong(meetingIdLong); 
      int a = Integer.parseInt(meetingIdLong); 
      intent.putExtra("meetingId", L); 

      Intent intent1 = new Intent(this, HomePage.class); 

      Intent intent2= new Intent(this, MeetingDetailPage.class); 
      intent2.putExtra("meetingId", L); 
      Intent intent3 = new Intent(this, MapPage.class); 
      intent3.putExtra("meetingId", L); 

      TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); 
      stackBuilder.addParentStack(ChatLog.class); 
      stackBuilder.addNextIntent(intent1); 
      stackBuilder.addNextIntent(intent2); 
      stackBuilder.addNextIntent(intent3); 
      stackBuilder.addNextIntent(intent); 

      PendingIntent pIntent = stackBuilder.getPendingIntent(a, PendingIntent.FLAG_UPDATE_CURRENT); 

      String notificationSound = _defPrefs.getString("pref_notification_tone", ""); 

      NotificationCompat.Builder noti = new NotificationCompat.Builder(this) 
      .setContentTitle(contactName) 
      .setContentText(chatMessage) 
      .setSmallIcon(R.drawable.noti_smallicon) 
      .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.noti_smallicon)) 
      .setSound(Uri.parse(notificationSound)) 
      .setDefaults(Notification.DEFAULT_VIBRATE) 
      .setNumber(++numberMsg) 
      .setAutoCancel(true) 
      .setContentIntent(pIntent); 

      NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); 
      String[] events = new String[6]; 
      events [numberMsg - 1] = new String(chatMessage); 

      // Sets a title for the Inbox style big view 
      inboxStyle.setBigContentTitle(contactName); 
      inboxStyle.setSummaryText(numberMsg + " new message(s)"); 

      for (int i=0; i < events.length; i++) { 

       inboxStyle.addLine(events[i]); 
      } 
      noti.setStyle(inboxStyle); 

      String isChatOpen, isChatOpenId; 

      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); 
      isChatOpen = preferences.getString("isChatOpen",""); 
      isChatOpenId = preferences.getString("isChatOpenId","0"); 

      if (!isChatOpenId.equals(meetingIdLong)) 
      { 
       NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
       notificationManager.notify(a, noti.build()); 
      } 

     } 
+0

여러 알림 의도를 시작하려면 각 알림에 전달되는 ID가 고유해야합니다. 그렇지 않으면 최신 알림이 다른 사람에게 겹쳐집니다. –

+0

@ Rat-a-tat-a-tatRatatouille 예, 제가 전달하는 chatId 여러 개의 알림을받을 수 있습니다. chatid 1의 알림을 클릭하면 chat id 2의 최신 의도가 결국 호출됩니다. – munfai

+0

이드를 사용하여 차별화 할 수 있습니까? 고유 한 ID를 전달하고 ID를 기반으로 한 활동에서 관련 표시 데이터를 표시합니다. –

답변

1

를 생성 코드의 조각이다. 그것의 다만 가짜 행동, 그러나 도움이된다.

관련 문제