J'ai trouvé cette bibliothèque (https://github.com/leolin310148/ShortcutBadger) pour implémenter le badge de compteur d'icône d'application dans android. badge fonctionne quand je l'implémente en activité. mais je veux implémenter ceci quand la notification de poussée est reçue. J'ai actuellement le code d'initialisation dans la méthode onMesseageReceived() dans le service de messagerie Firebase mais il ne fonctionne pas.Méthode FCM onReceived pour implémenter la bibliothèque Shortcut Badger
voir le code ci-dessous: Merci pour votre aide
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Logger.i("Received message");
//Shourtcut Badger
int badgeCount = 1;
ShortcutBadger.applyCount(context, badgeCount);
//parseNotification(bundle);
parseNotification(remoteMessage.getData());
if (remoteMessage.getData() != null) {
String str = remoteMessage.getData().get("notification");
String from_user = "";
String message = "";
String name = "";
int type = 0;
if (str != null && str.length() > 0) {
try {
JSONObject jobj = new JSONObject(str);
from_user = jobj.optString("from");
message = jobj.optString("message");
name = jobj.optString("name");
type = Integer.parseInt(jobj.optString("type"));
if (type == LIKE_STATUS) {
handleStatusLikeByFriendPush(jobj, "" + type);
} else if (type == PHOTO_UPDATE) {
handlePhotoUpdateByFriendPush(jobj, "" + type);
} catch (Exception e) {
e.printStackTrace();
}
} else {
message = "";//bundle.getString("message");
from_user = "";//bundle.getString("source");
if (from_user != null && from_user.contains(IMHandler.AT + IMHandler.DOMAIN)) {
from_user = from_user.substring(0, from_user.indexOf(IMHandler.AT));
}
showNotification(from_user, message, type, name);
}
}
}
public void handleStatusLikeByFriendPush(JSONObject jobj, String pushType) {
// method
}
public void handlePhotoLikeByFriendPush(JSONObject jobj, String pushType) {
// méthode mettre en œuvre }
}
private void showNotification(String from, String body, int type, String name) {
}
}