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);
}
あなたはこれをチェックしていますか? –