lazydroid/auto-update-apk-client

Not able to get notification in android Oreo.

Closed this issue · 1 comments

I tested the app on a phone running Nougat and it worked fine. But it doesnt show any notification when i use it on Oreo.

Okay so i resolved it.
Firstly add this permission to manifest:

<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>

Oreo uses channels for its notifications so add a check like this:

int importance = NotificationManager.IMPORTANCE_HIGH;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel mChannel = nm.getNotificationChannel(id);
            if (mChannel == null) {
                mChannel = new NotificationChannel(id,description,importance);
                mChannel.enableVibration(true);
                mChannel.setVibrationPattern(new long[]{400, 300, 200, 400});
                nm.createNotificationChannel(mChannel);
            }
        }

Lastly add the channel id to the builder :

NotificationCompat.Builder builder = new NotificationCompat.Builder(context,id);