Skip to content Skip to sidebar Skip to footer

Notificationcompat V7 Not Working On Oreo And Later Os Version

I am having troubles with NotificationCompat v7 on android 8,9 . whats the best way to show notification on all android version debug log android.app.RemoteServiceException: Bad

Solution 1:

You need use Notification Channel to display notification on Android 8.0+ device.

You can use below code to generate notification through your getShareThemNotification(...) method.

NotificationManagernotificationManager= (NotificationManager)
            context.getSystemService(Context.NOTIFICATION_SERVICE);

    Notification notification;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {

        NotificationChannelnotificationChannel=newNotificationChannel("channel_id",
                "Channel Name", NotificationManager.IMPORTANCE_HIGH);
        notificationChannel.enableLights(true);
        notificationChannel.setLightColor(Color.GREEN);
        notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
        notificationManager.createNotificationChannel(notificationChannel);

        Notification.Builderbuilder=newNotification.Builder(context, "channel_id");
        notification = builder.setContentTitle({"Title"})
                .setContentText({"Message"})
                .setAutoCancel(true)
                .setSmallIcon(R.drawable.ic_notification)
                .setContentIntent(pendingIntent).build();
    } else {
        Notification.Builderbuilder=newNotification.Builder(context);
        notification = builder.setContentTitle({"Title"})
                .setContentText({"Message"})
                .setAutoCancel(true) 
                .setSmallIcon(R.drawable.ic_notification)
                .setContentIntent(pendingIntent).build();
    }
    notificationManager.notify(id, notification);

Post a Comment for "Notificationcompat V7 Not Working On Oreo And Later Os Version"