我正在使用信标在检测到信标时显示通知。但是在Oreo设备中没有显示通知。它在Oreo版本以下的设备上运行良好。 我应该在通知部分还是在信标部分进行更改?
PS:我已经知道this链接有答案。我只是想确保更改是必须仅在通知部分中完成还是信标也应在其中进行。
答案 0 :(得分:0)
您必须在通知显示部分中进行更改。
这里是我使用的代码示例
private Notification createNotification(String msg, PendingIntent notificationPendingIntent) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
String CHANNEL_ID = "notification_chanel";// The id of the channel.
CharSequence name = "App name";// The user-visible name of the channel.
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance);
Notification notification = new Notification.Builder(this)
.setSmallIcon(R.drawable.logo_notext)
.setContentTitle("Geofence Notification!")
.setContentText(msg)
.setAutoCancel(true)
.setChannelId(CHANNEL_ID)
.setContentIntent(notificationPendingIntent).build();
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.createNotificationChannel(mChannel);
return notification;
} else {
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
notificationBuilder
.setSmallIcon(R.drawable.logo_notext)
.setColor(Color.RED)
.setContentTitle(msg)
.setContentText("Geofence Notification!")
.setContentIntent(notificationPendingIntent)
.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND)
.setAutoCancel(true);
return notificationBuilder.build();
}
}
希望它对您有帮助