2016-07-01 7 views
0

私のアプリケーションで通知するためのコードスニペットがあります。この結果はすべてのメッセージに対して新しい通知になります。複数のメッセージに対して1つの通知が必要です。私たちがSMS通知を受け取ったときに通知IDをキャッチする方法

NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(context); 

nBuilder.setSmallIcon(R.drawable.app_icon_indietext_new) 
         .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.app_icon_indietext_new)) 
         .setContentTitle(senderNum) 
         .setContentText(message) 
         .setAutoCancel(true); 

NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); 

      //String Number = nBuilder.toString(); 

      //create an intent to open a required activity 
      Intent nIntent = new Intent(context, ConvActivity.class); 
      nIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 

      //nIntent.putExtra(_id, threadId); 
      nIntent.putExtra(ADDRESS, senderNum); 

      //click action will be done by pendingIntent.send intent to the pendingIntent 
      PendingIntent nPendingInten = PendingIntent.getActivity(context, 0, nIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

      nBuilder.addAction(R.drawable.replyyyy, "Reply", nPendingInten); 
      String ThreadID = (String) nBuilder.getExtras().get(_id); 

      Random random = new Random(); 
      int m = random.nextInt(9999 - 1000) + 1000; 

      NotificationManager nNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
      TaskStackBuilder nStackBuilder = TaskStackBuilder.create(context); 
      nStackBuilder.addParentStack(ConvActivity.class); 

      nStackBuilder.addNextIntent(nIntent); 
      nBuilder.setContentIntent(nPendingInten); 

      Notification n = nBuilder.build(); 
      n.defaults |= Notification.DEFAULT_ALL; 
      nNotificationManager.notify(m,n); 

と、私は私のアプリを開くと、最初私はそれはそれは、送信者が既にある場合fine.iは同じ会話を開きたいですここconversation.uptoを開きます項目をクリックmessages.whenのリストですlist.how可能です。

答えて

1

すべてのuniqユーザにuniq indentifierを使用し、そのindentifierに基づいて通知することをお勧めします。多分あなたは数字のセリエAに送信者名を変換するコードの下に使用し、IDとして使用することができます:

String str = "abc"; 

StringBuilder sb = new StringBuilder(); for (char c : str.toCharArray()) sb.append((int)c); 

あなたのm値は:

BigInteger m = new BigInteger(sb.toString()); 

は私が正しくあなたの答えを理解していたホープは、あなたを助けます:)

+0

ありがとう、しかし私はnotify()の最初の引数は整数でなければならないと思う – venkatesh

+0

申し訳ありません申し訳ありませんが、コード行を見逃しました、そのBigにint、int i = m.intValue(); – KRist

+0

私は同じ目的とその罰金のために私のアプリで使用している...とにかくあなたがそれを解決することを願っ:) – KRist

関連する問題