gpt4 book ai didi

android - 未经 WRITE_SETTINGS 明确许可设置自定义铃声

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:18:23 30 4
gpt4 key购买 nike

我只是想设置铃声。我不想授予 WRITE_SETTINGS 权限,我可以找到大部分答案来授予 WRITE_SETTINGS 权限但是我正在使用一个应用程序,该应用程序没有设置铃声的 WRITE_SETTINGS 权限

https://play.google.com/store/apps/details?id=com.atomic.apps.ringtone.cutter

当您安装此应用时,它永远不会明确请求许可 android.permission.WRITE_SETTINGS(也在棉花糖中)

这是从存储中提取铃声的方法

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)

请帮忙。提前致谢。

最佳答案

必须在您的代码中使用 android.permission.WRITE_SETTINGS 并要求用户明确授予此权限才能使您的代码/应用程序正常工作。没有使用 WRITE_SETTINGS 权限,没有其他人可以这样做。

此外,您提到的来自 Google 的应用程序也在使用此WRITE_SETTINGS 权限(修改系统设置)。查看以下屏幕截图以获取更多信息:

enter image description here

关于如何使用 WRITE_SETTINGS 请查看以下引用资料:

  1. 官方文档:https://developer.android.com/reference/android/Manifest.permission#WRITE_SETTINGS
  2. 关于 SO 的最佳答案之一:https://stackoverflow.com/a/32083622/631803

关于android - 未经 WRITE_SETTINGS 明确许可设置自定义铃声,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50857936/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com