0

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();
    }
season
  • 336
  • 3
  • 13
  • 1
    Notification architecture is changed with Android Oreo, you need to add Notification Channel.https://stackoverflow.com/questions/43093260/notification-not-showing-in-oreo – tejendra singh Sep 04 '18 at 09:05
  • i have used the notification channel and updated the question including channel ,,it didnt work for me can you check please – season Sep 04 '18 at 09:11

0 Answers0