https://play.google.com/store/apps/details?id=com.atomic.apps.ringtone.cutter
当您安装此应用时,它永远不会明确地询问权限android.permission.WRITE_SETTINGS(也在marshmallow中)
这是从存储中选择铃声的方法
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);
}
//这里我要设置铃声
@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);
}
}
}
}
但我收到此错误
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)
请帮忙。 提前谢谢。
答案 0 :(得分:5)
您必须在代码中使用 android.permission.WRITE_SETTINGS
并要求用户明确授予此权限以使您的代码/应用程序正常运行。没有WRITE_SETTINGS
权限,没有其他人可以做到这一点。
此外,您提到的Google应用程序也使用此WRITE_SETTINGS
权限(修改系统设置)。请查看以下屏幕截图以获取更多信息:
如何使用WRITE_SETTINGS
检查以下参考资料:
答案 1 :(得分:3)
使用方式必须使用android.permission.WRITE_SETTINGS
我只安装了该应用程序,然后查看他的使用方式,我相信两件事