1
sendNotification('Hello', 0, 1); 

private void sendNotification(String message, int id, int notification_num) { 

    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

    Intent intent = new Intent(this, Main.class); 
    intent.setData(new Uri.Builder().scheme("data").build()); 
    intent.putExtra("id", id); 
    intent.putExtra("noti_number", notification_num); 
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); 
    stackBuilder.addParentStack(Main.class); 
    stackBuilder.addNextIntent(intent); 

    PendingIntent pendingIntent = PendingIntent.getActivity(this, id, intent, 
      PendingIntent.FLAG_UPDATE_CURRENT); 

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
      .setContentTitle("App Title") 
      .setContentText(message) 
      .setSmallIcon(R.drawable.notif) 
      .setAutoCancel(true) 
      .setSound(defaultSoundUri) 
      .setContentIntent(pendingIntent); 
    notificationBuilder.setNumber(notification_num); 
    nm.notify(id, notificationBuilder.build()); 

} 

アプリケーションが開かれると、intent.putExtraはうまく動作しますが、アプリを終了すると(kill proccess)、新しい意図が余分に追加されています。バックグラウンドでのAndroid通知

問題は複数の通知でも、アプリケーションが閉じているときには、私がしたいようなグループ化はありません。 notificationBuilder.setNumberはバックグラウンドで常に0です。

いつもバックグラウンドでアプリを実行する方法や以前のインテントを続ける方法を助けてください。

答えて

0

私はこれをGcmIntentService & GcmBroadcastReceiverを使用して行っています。詳細はon this linkをクリックしてください。

関連する問題