Je souhaite mettre à jour le badge en arrière-plan et j'utilise le style de notification, mais cela n'a pas fonctionné. Je ne veux pas utiliser le style de données car une seule notification est apparue. S'il vous plaît aider Je veux vérifier pousser à l'arrière sol et mise à jour badgesLe badge Android FCM ne fonctionnait pas en arrière-plan
public void zzm(Intent intent) {
Set<String> keys = intent.getExtras().keySet();
for (String key : keys) {
try {
if (key.equals("badge")) {
String cnt = intent.getExtras().get(key).toString();
int badgeCount = Integer.valueOf(cnt);
ShortcutBadger.applyCount(this, badgeCount);
}
} catch (Exception e) {
Log.i("uniqbadge", "zzm Custom_FirebaseMessagingService" + e.getMessage());
}
}
super.zzm(intent);
}
// ce code est reçu
public void onMessageReceived(RemoteMessage remoteMessage) {
showNotification(remoteMessage.getData().get("title"), remoteMessage.getData().get("message"));
set_alarm_badge();
}
// ma notification mise
private void showNotification(String title, String message) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
// ceci est mon mise à jour du badge
public void set_alarm_badge(){
Context context=getApplicationContext();
Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
MainActivity.badge_count++;
intent.putExtra("badge_count", MainActivity.badge_count);
intent.putExtra("badge_count_package_name",getApplicationContext().getPackageName());
intent.putExtra("badge_count_class_name",MainActivity.class.getName());
if(Build.VERSION.SDK_INT> Build.VERSION_CODES.GINGERBREAD_MR1) {
intent.setFlags(0x00000020);
}
if (canResolveBroadcast(getApplicationContext(), intent)) {
Log.d("TAG", "hi ");
getApplicationContext().sendBroadcast(intent);
}
}