2017-08-10 4 views
0

firebase上にプッシュ通知アプリを作成すると、すべて正常に動作します。新しい通知を受け取るたびに、アプリにバッジを追加してアイコンに+1する必要があります。それを行う方法を知らない... この私のコードアイコンバッジ通知

public void onMessageReceived(RemoteMessage remoteMessage) { 
    if(remoteMessage.getData().size() >0){ 
     type="json"; 
     sendNotificatio(remoteMessage.getData().toString()); 
    } 
    if(remoteMessage.getNotification() !=null) { 
     type = "message"; 
     sendNotificatio(remoteMessage.getNotification().getBody()); 
    } 
} 
public void sendNotificatio(String messageBody) { 
    String id=""; 
    String message=""; 
    String titles=""; 

    if (type.equals("json")){ 
     try { 
      JSONObject jsonObject = new JSONObject(messageBody); 
      id=jsonObject.getString("id"); 
      message=jsonObject.getString("message"); 
      titles= jsonObject.getString("title"); 
     } catch (JSONException e) { 
      e.printStackTrace(); 
     } 

    } else if (type.equals("message")) { 
     message= messageBody; 
    } 
    Intent i = new Intent(FCM_service.this,Mensage.class); 
    i.putExtra("id",id); 
    i.putExtra("message",message); 
    i.putExtra("titles",titles); 

    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

    PendingIntent pendingIntent = PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_ONE_SHOT); 

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this) 
      .setAutoCancel(true) 
      .setContentTitle(titles) 
      .setContentText(message) 
      .setSmallIcon(R.mipmap.ic_launcher) 
      .setContentIntent(pendingIntent); 
    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    manager.notify(0,builder.build()); 
    Log.d("LOGTA", "NOTIFICACION RECIBIDA"); 
    Log.d("LOGTAG", "Título:" + titles); 
    Log.d("LOGTAG", "Texto: " + message); 
    String dato = message; 
    i.putExtra("MENSAJE", dato); 
    Log.e("Mensajito", dato); 

} 

答えて

0

あなたが優先して現在のカウントを格納する必要があり、通知は、あなたのonMessageReceivedに来るとき、あなたはあなたのカウントそのうち1つの増分値でbroadcast Receiverを送信する必要が後優先的です。そしてあなたが見せたいところで放送を受信して​​ください。

+0

あなたはこれをチェックしていますか? –