【发布时间】:2020-05-05 14:38:02
【问题描述】:
我真的需要你的帮助。目前,我正在我的应用程序中开发通知模块。我的问题是通知适用于奥利奥,但不适用于奥利奥和派。我正在使用 mi(小米)设备,下面是我的代码:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = notificationManager.getNotificationChannel(CHANNEL_ID);
if (channel == null){
channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
channel.enableLights(true);
channel.enableVibration(true);
channel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
AudioAttributes att = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.build();
channel.setSound(Uri.parse(sound), att);
notificationManager.createNotificationChannel(channel);
}
mBuilder = new NotificationCompat.Builder(mContext, CHANNEL_ID);
mBuilder.setSmallIcon(icon)
.setTicker(message)
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setContentTitle(title)
.setContentIntent(resultPendingIntent)
.setSound(Uri.parse(sound))
.setLights(0xff00ff00, 500, 500)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(notificationVO.getMessage()))
.setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon))
.setContentText(message)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setVibrate(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
}
我的问题的细节是,当条件打开但没有声音、振动时,正在通过电话接收通知。在锁屏状态下,通知不显示,没有指示灯,没有振动,没有声音。
有谁知道如何解决这个问题?谢谢大家,非常感谢您的帮助
【问题讨论】:
-
请推送整个代码以设置通知(例如在哪里调用 mBuilder.build() 等)?
-
我使用这个链接作为我的参考:stackoverflow.com/a/46991229/11851867
-
你能在小米以外的其他安卓奥利奥设备上测试它吗?
-
不幸的是我没有比小米其他的奥利奥设备。我想我会关闭这个问题并将您的答案标记为已接受,因为目前我决定实施您关于直接用户到通知设置的解决方案,同时我将继续试验并等待谷歌和其他开发人员的更新以优化所有 android 设备的通知开发从奥利奥开始。感谢您的解决方案,我真的很感激。
-
也试试this之类的小技巧,看看能不能解决你的小米通知问题?