0

I am using beacons to display a notification when a beacon is detected. But no notification is displayed in Oreo devices. It works well in devices below Oreo version. Should I make changes in the notification section or in the beacon part?

PS : I already know that this link has an answer. I just wanted to make sure if the changes must be done in the notification section alone or beacons also play a part in it.

Nikmaniac
  • 29
  • 6

1 Answers1

0

you have to make change in the notification display section .

here a sample of code which i used

 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();
    }
}

Hope it helps you

hamza khan
  • 141
  • 1
  • 11
  • Thank you so much! This works. But the issue is..the notification is not displayed when the app is killed. What is the solution for that? – Nikmaniac Oct 05 '18 at 06:43