Setting a ringtone from my raw folder in Android

I am trying to read / access the mp3 file in my Raw folder and then set it as the default ringtone. But he cannot find him.

My code is

                Uri path = Uri.parse("android.resource://com.applenty/LearnToCount/raw/mysoundfile");
            RingtoneManager.setActualDefaultRingtoneUri(
                    getApplicationContext(), RingtoneManager.TYPE_RINGTONE,
                    path);
            Log .i("TESTT", "Ringtone Set to Resource: "+ path.toString());
            RingtoneManager.getRingtone(getApplicationContext(), path)
                    .play();

Is it really wrong here? I tried all kinds of combinations here

+5
source share
1 answer

This works for me. (remove LearnToCount)

Uri path = Uri.parse("android.resource://com.applenty/raw/mysoundfile");

And then in your manifest.

<uses-permission android:name="android.permission.WRITE_SETTINGS"></uses-permission>
+8
source

All Articles