使用未在 Oreo 设备中检测到的信标进行通知
Notification using beacons not detected in Oreo devices
我正在使用信标在检测到信标时显示通知。但是 Oreo 设备中没有显示任何通知。它适用于奥利奥版本以下的设备。
我应该在通知部分或信标部分进行更改吗?
PS : 我已经知道 link 有答案了。我只是想确定更改是否必须单独在通知部分完成,或者信标也参与其中。
您必须在通知显示部分进行更改。
这里是我使用的代码示例
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();
}
}
希望对你有帮助
我正在使用信标在检测到信标时显示通知。但是 Oreo 设备中没有显示任何通知。它适用于奥利奥版本以下的设备。 我应该在通知部分或信标部分进行更改吗?
PS : 我已经知道
您必须在通知显示部分进行更改。
这里是我使用的代码示例
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();
}
}
希望对你有帮助