2017-08-10 116 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那么之后你必须发送broadcast Receiver与你计数的一个增量值是优先的。并接收您想要播放的节目。

+0

你有没有检查过? –