gpt4 book ai didi

Android O 报告通知未发布到 channel - 但它是

转载 作者:IT王子 更新时间:2023-10-29 00:02:13 24 4
gpt4 key购买 nike

几个 Android O 通知问题:

1) 我创建了一个通知 channel (见下文),正在使用 .setChannelId() 调用构建器(传入我创建的 channel 的名称“wakey”;但是,当我运行应用程序时,我收到一条消息,说我未能向 channel “null”发布通知。这可能是什么原因?

2) 我怀疑#1 的答案可以在它说要检查的“日志”中找到,但我已经检查了 logcat 并且没有看到任何关于通知或 channel 的信息。它说要查看的日志在哪里?

这是我用来创建 channel 的代码:

NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence name = context.getString(R.string.app_name);
String description = "yadda yadda"
int importance = NotificationManager.IMPORTANCE_DEFAULT;

NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL, name, importance);
channel.setDescription(description);

notificationManager.createNotificationChannel(channel);

这是生成通知的代码:

Notification.Builder notificationBuilder;

Intent notificationIntent = new Intent(context, BulbActivity.class);
notificationIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); // Fix for https://code.google.com/p/android/issues/detail?id=53313

PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

Intent serviceIntent = new Intent(context, RemoteViewToggleService.class);
serviceIntent.putExtra(WakeyService.KEY_REQUEST_SOURCE, WakeyService.REQUEST_SOURCE_NOTIFICATION);

PendingIntent actionPendingIntent = PendingIntent.getService(context, 0, serviceIntent, PendingIntent.FLAG_CANCEL_CURRENT);
_toggleAction = new Notification.Action(R.drawable.ic_power_settings_new_black_24dp, context.getString(R.string.toggle_wakey), actionPendingIntent);

notificationBuilder= new Notification.Builder(context)
.setContentTitle(context.getString(R.string.app_name))
.setContentIntent(contentIntent)
.addAction(_toggleAction);

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
notificationBuilder.setChannelId(NOTIFICATION_CHANNEL);
}

notificationBuilder.setSmallIcon(icon);
notificationBuilder.setContentText(contentText);
_toggleAction.title = actionText;

int priority = getNotificationPriority(context);
notificationBuilder.setPriority(priority);
notificationBuilder.setOngoing(true);

Notification notification = notificationBuilder.build();
notificationManager.notify(NOTIFICATION_ID, notification);

这是我收到的警告: enter image description here

最佳答案

我想我已经学到了一些东西,这些东西加起来就是一个答案:

  1. 我使用的是模拟器设备,其中的图片不包含 Play 商店。
  2. 图片上的 Google Play 服务版本不是最新版本,所以我应该收到通知,告诉我需要升级。由于该通知未应用于 channel ,因此未显示。
  3. 如果我在 Android Studio 中将 logcat 设置为“无过滤器”而不是“仅显示选定的应用程序”,那么我发现日志指出有问题的通知是 Play Services“需要更新”通知。

所以,我换了一张包含 Play 商店的图片,它正确显示了通知(也许该通知的 channel 是由 Play 商店设置的?),让我更新到最新的 Google Play 服务,从那以后我就再也没有看到过这个警告。

所以,长话短说(为时已晚) - 对于 Android O,如果您在模拟器上使用 Google Play 服务和测试,请选择包含 Play 商店的图像,或者忽略 toast(祝您好运! )。

关于Android O 报告通知未发布到 channel - 但它是,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44489657/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com