【发布时间】:2020-01-12 01:54:44
【问题描述】:
我尝试使用下一个代码为广播接收器启动活动
Intent i = new Intent(context, AlarmNotification.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { // This is at least android 10...
NotificationManager mgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (mgr.getNotificationChannel(CHANNEL_WHATEVER)==null) {
mgr.createNotificationChannel(new NotificationChannel(CHANNEL_WHATEVER,
"Whatever", NotificationManager.IMPORTANCE_HIGH));
}
mgr.notify(NOTIFY_ID, buildNormal(context, i).build());
}
private NotificationCompat.Builder buildNormal(Context context, Intent intent) {
NotificationCompat.Builder b=
new NotificationCompat.Builder(context, CHANNEL_WHATEVER);
b.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setSmallIcon(android.R.drawable.ic_lock_idle_alarm)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(TEXT)
.setContentText(TEXT)
.setFullScreenIntent(buildPendingIntent(context, intent), true);
return(b);
}
private PendingIntent buildPendingIntent(Context context, Intent intent) {
return(PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
}
一开始,一切都很好。但是如果我进入应用设置,关闭CHANNEL_WHATEVER的通知通道,然后再打开。稍后当我调用 NotificationManager.notify 时,它会在通知抽屉中显示通知,但不会启动活动。如果我删除该应用程序并重新安装,它会再次正常工作。这是我应该报告的android 10的错误,还是我可以做些什么?
【问题讨论】:
-
禁用然后启用该频道后,该频道上的所有其他选项是否与“设置”中的相同?如果您由于禁用/启用周期而在该频道上丢失
IMPORTANCE_HIGH,则您的症状匹配。 -
@CommonsWare 如何判断我是否丢失了 IMPORTANCE_HIGH?如果是这样,我该怎么办?
-
“如果是这样,我该怎么办?” - 没有,除了可能提交错误报告。 “我怎么知道我是否丢失了 IMPORTANCE_HIGH?” -- 以编程方式,当
mgr.getNotificationChannel(CHANNEL_WHATEVER)不是null时,您应该能够查看它的结果。致电getImportance()并记录您看到的值。 -
@CommonsWare 你说得对。重要性从 IMPORTANCE_HIGH 变为 IMPORTANCE_LOW。我会举报的。
-
@SimpleUXApps 我也面临同样的问题。你是如何设法让它工作的?请发布或接受答案。
标签: android android-intent broadcastreceiver android-pendingintent android-10.0