我正在通过意图使用Geofence
触发服务,因此下面的代码适用于oreo以下的版本,但是我遇到的问题是Geofence
被完美触发但通知的oreo版本不管用。我还在电话中启用了通知功能,并将优先级设置为“高”。请向我建议解决方案。
这是GeofenceTransitionservice.java
private void sendNotification(String msg) {
// Intent to start the Maps Activity
Intent notificationIntent = MapsActivity.makeNotificationIntent(getApplicationContext(),
msg
);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MapsActivity.class);
stackBuilder.addNextIntent(notificationIntent);
PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
// Creating and sending Notification
NotificationManager notificatioMng =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificatioMng.notify(
GEOFENCE_NOTIFICATION_ID,
createNotification(msg, notificationPendingIntent));
}
// Create notification
private Notification createNotification(String msg, PendingIntent notificationPendingIntent) {
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "my_channel_id_01");
notificationBuilder
.setSmallIcon(R.drawable.logo)
.setContentTitle(msg)
.setContentText("Notification")
.setContentIntent(notificationPendingIntent)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setWhen(System.currentTimeMillis())
.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND)
.setAutoCancel(true);
return notificationBuilder.build();
}