我想使用 Firebase 消息传递将数字(通知计数)显示为徽章,在 Android 10 或更低版本上一切正常,但没有选项可以在应用程序的“管理通知”设置中将通知徽章类型设置为数字,我可以查看适用于 Facebook 或 Whatsapp 的选项。我的清单文件中是否缺少任何权限或任何内容,或者如何在 Android 11 的应用程序中添加此选项?
我已经创建了一个广播接收器并注册了它,但我无法接收 Intent.ACTION_PACKAGE_ADDED 事件。
val intentFilter = IntentFilter().apply {
addAction(Intent.ACTION_PACKAGE_ADDED)
addAction(Intent.ACTION_PACKAGE_REMOVED)
addDataScheme("package")
}
intentFilter.priority = 999
val rec = IntentReceiver()
registerReceiver(rec, intentFilter)
Run Code Online (Sandbox Code Playgroud)
这是我的 BroadcastReceiver 类
class IntentReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
Toast.makeText(context, "TEST TOAST", Toast.LENGTH_LONG).show()
val builder =
NotificationCompat.Builder(context!!, "worker_channel")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("App is installed")
.setPriority(NotificationCompat.PRIORITY_HIGH)
val notificationManager: NotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(4, builder.build())
}}
Run Code Online (Sandbox Code Playgroud)
我没有收到任何事件,但是相同的广播接收器适用于以下意图:
Intent.ACTION_PACKAGE_REMOVED
Intent.ACTION_AIRPLANE_MODE_CHANGED
Run Code Online (Sandbox Code Playgroud)
而且我还在 Logcat 中获取 PACKAGE_ADDED 事件的日志,如下所示
W/BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_ADDED dat=package:com.socialnmobile.dictapps.notepad.color.note flg=0x4000010 (has …Run Code Online (Sandbox Code Playgroud)