G
G
Geradot2020-10-30 15:18:52
Android
Geradot, 2020-10-30 15:18:52

How to enable sound and popup for heads-up notifications for android 8.1+ app?

Notification sound not working in android 9 on 7 phones, notification does not pop up. If you turn on sound and pop-up notifications in the application settings, everything works correctly.

I add a channel like this:

final NotificationManager notificationManager = (NotificationManager) cordova.getActivity()
          .getSystemService(Context.NOTIFICATION_SERVICE);

        String appName = this.getAppName();
        NotificationChannel mChannel = new NotificationChannel(DEFAULT_CHANNEL_ID, appName,
            NotificationManager.IMPORTANCE_HIGH);
        mChannel.setDescription(appName);
        mChannel.setImportance(NotificationManager.IMPORTANCE_HIGH);
        mChannel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PUBLIC);
        mChannel.enableVibration(true);
        mChannel.setVibrationPattern(new long[] { 100, 1000, 500, 1000 });
        mChannel.setShowBadge(true);
        mChannel.setBypassDnd(true);
        mChannel.enableLights(true);
        mChannel.setLightColor(Color.WHITE);
        AudioAttributes audioAttributes = new AudioAttributes.Builder()
                                .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                                .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                                .build();
        mChannel.setSound(soundUri, audioAttributes);
        notificationManager.createNotificationChannel(mChannel);


most often the problem appears on xiaomi devices.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Maslennikov, 2020-10-30
@SOM4

But the application itself cannot bypass the OS limitation. At least in 4.4 (KitKat), when the last time I played with notifications, it was like that.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question