Tuesday, 22 January 2019

Is it possible to adjust notification sound volume dynamically in Android O and above?

I fully understand since Android O and above, there's no easy way to customize notification sound through app's code.

The common way to do so, is to invoke Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS

private void showNotificationSoundListPreferenceDialogFragmentCompat(Preference preference) {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
        intent.putExtra(Settings.EXTRA_APP_PACKAGE, getContext().getPackageName());
        intent.putExtra(Settings.EXTRA_CHANNEL_ID, com.yocto.wenote.reminder.Utils.createNotificationChannel());
        try {
            startActivity(intent);
        } catch (android.content.ActivityNotFoundException e) {
            Log.e(TAG, "", e);
            trackEvent("showNotificationSoundListPreferenceDialogFragmentCompat", "fatal", e.getMessage());
        }
    }
}

It looks like following

enter image description here

However, I notice some apps in the market, do provide way to adjust notification sound volume dynamically.

enter image description here

May I know, what is the way to achieve so?



from Is it possible to adjust notification sound volume dynamically in Android O and above?

No comments:

Post a Comment