【问题标题】:Notification Count Badge in Android App IconAndroid 应用程序图标中的通知计数徽章
【发布时间】:2017-07-12 17:30:51
【问题描述】:
我正在开发 android 应用程序,我正在使用 Firebase 云消息传递服务向用户发送通知。为了让用户更加了解通知,我想在应用程序的启动器图标上显示通知的数量。
有什么办法吗?
我不想创建小部件。
我试过库 ShortcutBadger Link for the Library
但是这个库的问题是当应用程序处于后台或被杀死时它不起作用?
我在我的应用程序的 BroadcastReceiver 中使用了计数更新方法
有人可以建议如何使用它或更好的方法吗?
【问题讨论】:
标签:
android
firebase
push-notification
firebase-cloud-messaging
android-launcher
【解决方案1】:
如果您有自己的 FirebaseMessagingService,您可以在 onCreate 中设置您的徽章计数。
public class MyFirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {
@Override
public void onCreate() {
super.onCreate();
ShortcutBadger.applyCount(MyFirebaseMessagingService.this, 1);
}
}
onCreate 将在通知到达时触发。
希望对你有帮助。
【解决方案3】:
所以,为了在收到通知时不管应用程序的状态如何在应用程序中采取一些行动,那么我们需要发送通知的数据类型。 onMessageReceived() 的 FireabaseMessagingService 方法总是被触发,无论应用程序状态是向用户发送通知的数据类型,否则如果通知对象还包含通知字段,则系统托盘本身会处理设备和应用程序中的通知填充没有任何踪迹。