I'm using the Geofence
triggering service using intent so this code below works for the versions below oreo but I am facing the problem in the oreo version where the Geofence
gets triggered perfectly but the notification is not working. I also have enabled the notification in the phone and set priority to high.please do suggest me the solutions.
here is the code for the 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();
}