Skip to content Skip to sidebar Skip to footer

Set As Default Ringtone From Raw Folder Programmatically In Android

I tried this code its working fine to load the sound file to ringtones directory.I can manually select the sound from popup ..but its fail to set as default ringtone programmatical

Solution 1:

Remove this code RingtoneManager.getRingtone(context,this.getContentResolver() .insert(MediaStore.Audio.Media.getContentUriForPath(k .getAbsolutePath()), values));

and put these lines code before return true and its work

 Uri newUri = this.getContentResolver()
            .insert(MediaStore.Audio.Media.getContentUriForPath(k
                    .getAbsolutePath()), values);
    RingtoneManager.setActualDefaultRingtoneUri(MainActivity.this, RingtoneManager.TYPE_RINGTONE, newUri);

Solution 2:

try {
                Urinotification= Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.phone_funny_bell);
                Ringtoner= RingtoneManager.getRingtone(getApplicationContext(), notification);
                r.play();

                newHandler().postDelayed(newRunnable() {
                    @Overridepublicvoidrun() {
                        r.stop();
                    }
                }, 3000);
            } catch (Exception e) {
                e.printStackTrace();
            }

Use this one. This will work.

place above code on MyFirebaseMessagingService inside this onMessageReceived

Post a Comment for "Set As Default Ringtone From Raw Folder Programmatically In Android"