I simple want to set the ringtone. I don't want to give permission of WRITE_SETTINGS, i can find most of the answer to give permission of WRITE_SETTINGS but there is an app i am using that app has not any WRITE_SETTINGS permission to set the ringtone
https://play.google.com/store/apps/details?id=com.atomic.apps.ringtone.cutter
When you install this app it never ask permission explicitly android.permission.WRITE_SETTINGS (also in marshmallow)
this is the method to pick the ringtone from storage
public void pickRingtone()
{
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Ringtone");
Uri urie = RingtoneManager.getActualDefaultRingtoneUri(getApplicationContext(), RingtoneManager.TYPE_RINGTONE);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, urie);
startActivityForResult(intent, REQUEST_CODE);
}
// here i am going to set the ringtone
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == REQUEST_CODE) {
if (resultCode == RESULT_OK)
{
Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
if (uri != null)
{
String ringTonePath = uri.toString();
RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE, uri);
}
}
}
}
but i am getting this error
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=5, result=-1, data=Intent { dat=content://com.mi.android.globalFileexplorer.myprovider/external_files/Download/Amazing Amitabh Bachchan Voice Motivational pink film poem Tu khud ki khoj me nikal (192 kbps).mp3 flg=0x1 (has extras) }} to activity {com.example.himanshu.defaultringtone/com.example.himanshu.defaultringtone.MainActivity}: java.lang.SecurityException: com.example.himanshu.defaultringtone was not granted this permission: android.permission.WRITE_SETTINGS.
at android.app.ActivityThread.deliverResults(ActivityThread.java:4162)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4205)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1572)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6221)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
Caused by: java.lang.SecurityException: com.example.himanshu.defaultringtone was not granted this permission: android.permission.WRITE_SETTINGS.
at android.os.Parcel.readException(Parcel.java:1684)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
at android.content.ContentProviderProxy.call(ContentProviderNative.java:646)
at android.provider.Settings$NameValueCache.putStringForUser(Settings.java:1601)
at android.provider.Settings$System.putStringForUser(Settings.java:1992)
at android.media.RingtoneManager.setActualDefaultRingtoneUri(RingtoneManager.java:666)
at com.example.himanshu.defaultringtone.MainActivity.onActivityResult(MainActivity.java:77)
Please help. Thanks in advance.
You must have to use android.permission.WRITE_SETTINGS
in your code and ask user to explicitly grant this permission to make your code/application work. There is no other to do that without the use of WRITE_SETTINGS
permission.
Also the application from Google you have mentioned is also using this WRITE_SETTINGS
permission (modify system settings). Check the below screenshot for more information:
For how to use WRITE_SETTINGS
check below references:
The way you use you must have to use android.permission.WRITE_SETTINGS
I just install that app and looking the way he uses I believe in 2 things
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With