android o 通知渠道,Android O报告通知未发布到频道 – 但确实如...

几个Android O通知问题:

1)我创建了一个Notification Channel(见下文),用.setChannelId()调用构建器(传入我创建的频道的名称,“wakey”;然而,当我运行应用程序时,我收到一条消息我没有向渠道“null”发布通知.可能是什么导致了这个?

2)我怀疑#1的答案可以在它要检查的“日志”中找到,但我已经检查过logcat&看不到有关通知或频道的任何信息.它说要查看的日志在哪里?

这是我用来创建频道的代码:

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);

这是我得到的警告:

A4jbH.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值