Android 应用程序图标中的通知计数徽章
Notification Count Badge in Android App Icon
我正在开发 android 应用程序,我在其中使用 Firebase 云消息服务向用户发送通知。为了让用户更加了解通知,我想在应用程序的启动器图标上显示通知的数量。
有什么办法吗?
我不想创建小部件。
我试过库 ShortcutBadger Link for the Library
但是这个库的问题是当应用程序在后台或被杀死时它不工作?
我在我的应用程序的BroadcastReceiver中使用了计数更新方法
有人可以建议如何使用它或更好的方法吗?
Android O介绍通知徽章:
https://developer.android.com/preview/features/notification-badges.html
它们通过长按图标显示通知数量。不过,O 得到广泛采用还需要一段时间。
如果您有自己的 FirebaseMessagingService,您可以在 onCreate 中设置徽章计数。
public class MyFirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {
@Override
public void onCreate() {
super.onCreate();
ShortcutBadger.applyCount(MyFirebaseMessagingService.this, 1);
}
}
onCreate 将在通知到达时触发。
希望对你有帮助。
因此,为了在收到通知时在应用中采取一些操作,而不管应用的状态如何,我们需要发送通知的数据类型。 onMessageReceived()
FireabaseMessagingService
方法始终被触发,无论应用程序状态是用户发送通知的数据类型,否则如果通知对象还包含通知字段,则系统托盘本身会处理通知的填充设备和应用程序没有它的踪迹。
我正在开发 android 应用程序,我在其中使用 Firebase 云消息服务向用户发送通知。为了让用户更加了解通知,我想在应用程序的启动器图标上显示通知的数量。 有什么办法吗? 我不想创建小部件。 我试过库 ShortcutBadger Link for the Library
但是这个库的问题是当应用程序在后台或被杀死时它不工作?
我在我的应用程序的BroadcastReceiver中使用了计数更新方法
有人可以建议如何使用它或更好的方法吗?
Android O介绍通知徽章:
https://developer.android.com/preview/features/notification-badges.html
它们通过长按图标显示通知数量。不过,O 得到广泛采用还需要一段时间。
如果您有自己的 FirebaseMessagingService,您可以在 onCreate 中设置徽章计数。
public class MyFirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {
@Override
public void onCreate() {
super.onCreate();
ShortcutBadger.applyCount(MyFirebaseMessagingService.this, 1);
}
}
onCreate 将在通知到达时触发。 希望对你有帮助。
因此,为了在收到通知时在应用中采取一些操作,而不管应用的状态如何,我们需要发送通知的数据类型。 onMessageReceived()
FireabaseMessagingService
方法始终被触发,无论应用程序状态是用户发送通知的数据类型,否则如果通知对象还包含通知字段,则系统托盘本身会处理通知的填充设备和应用程序没有它的踪迹。