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

enter image description here

However, I notice some apps in the market, do provide way to adjust notification sound volume dynamically. May I know, what is the way to achieve so?

asked Dec 24, 2018 at 7:49 Cheok Yan Cheng Cheok Yan Cheng 44.7k 138 138 gold badges 486 486 silver badges 928 928 bronze badges What do you mean about "Dynamically"? Just increase/decrease its volume? Commented Jan 22, 2019 at 19:09

You can adjust the volume via app, and such volume adjustment only specifically targetting this app, not entire device

Commented Jan 23, 2019 at 0:24 Could you introduce a program which does this? Commented Jan 24, 2019 at 11:02 @CheokYanCheng Im wondering if i answered your question correctly? Commented Jan 30, 2019 at 10:37 @aminography play.google.com/store/apps/… Commented Jan 30, 2019 at 15:14

2 Answers 2

This is merely a hack, a way to get it to do so, and it will achieve your required behavior. In my application, targeting API 26; i have implemented a sound and vibration customization but manually.

NotificationCompat.Builder notification = new NotificationCompat.Builder(this, "Channel1"); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) < // Vibrations Vibrator vib = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE); vib.vibrate(VibrationEffect.createWaveform(new long[] , 1)); //Sound Intent soundIntent = new Intent(this, PlaySound.class); serviceIntent.setAction("ACTION_START_PLAYBACK"); serviceIntent.putExtra("UriSound", soundUri.toString()); context.startForegroundService(soundIntent); // if notification is outted, just delete notification; thus delete intent Intent outNotification = new Intent(context, PlaySound.class); deleteIntent.setAction("ACTION_STOP_PLAYBACK"); PendingIntent pendingOutNotification = PendingIntent.getService(this, 0, outNotification, 0); builder.setDeleteIntent(pendingOutNotification); > else < builder.setVibrationPattern(new long[]); builder.setSound(uri); > notificationManager.notify(0, builder.build()); 

In your PlaySound.class extend service , Play your sound on a media player , and control volume or the particular sound based on the intent of that particular channel .

Target the volume or the uri based on the users input from the slider, and then send via intent or save it in a key-value pair using sharedpreference s.