我正在开发一个应用程序,它将从用户已经选择的音调列表中随机设置铃声。
虽然我的代码适用于Android N及更高版本,但我遇到Android M及以下版本的问题。我经常搜索解决方案。但找不到任何。
以下是我设置铃声的代码段。
RingtoneManager.setActualDefaultRingtoneUri(getApplicationContext(),
RingtoneManager.TYPE_RINGTONE,
uri);
这是我的清单文件。
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
以下是应用程序运行时生成的错误日志
11-11 09:09:32.914 3292-3292/? W/Binder_1: type=1400 audit(0.0:32): avc: denied { read } for path="/storage/emulated/0/iphone6.mp3" dev="fuse" ino=23 scontext=u:r:system_server:s0 tcontext=u:object_r:fuse:s0 tclass=file permissive=0
11-11 09:09:32.935 1611-3697/system_process E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 336)
11-11 09:09:32.935 1611-3697/system_process I/ActivityThread: Removing dead content provider:android.content.ContentProviderProxy@b69350e
11-11 09:09:32.937 1611-3697/system_process W/ActivityManager: unstableProviderDied: caller 1000 says ContentProviderConnection{ca0b2f/com.android.externalstorage/.ExternalStorageProvider->1611:system/1000 s0/0 u1/1 +23ms} died, but we don't agree
11-11 09:09:32.934 3292-3292/? W/Binder_1: type=1400 audit(0.0:33): avc: denied { read } for path="/storage/emulated/0/iphone6.mp3" dev="fuse" ino=23 scontext=u:r:system_server:s0 tcontext=u:object_r:fuse:s0 tclass=file permissive=0
11-11 09:09:32.954 1611-3697/system_process E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 336)
11-11 09:09:32.954 1611-3697/system_process W/MediaPlayer: Couldn't open file on client side; trying server side: java.io.FileNotFoundException: Failed opening content provider: content://com.android.externalstorage.documents/document/primary%3Aiphone6.mp3
11-11 09:09:32.963 1611-3697/system_process W/ActivityManager: Permission Denial: opening provider com.android.externalstorage.ExternalStorageProvider from (null) (pid=1328, uid=1013) requires android.permission.MANAGE_DOCUMENTS or android.permission.MANAGE_DOCUMENTS
11-11 09:09:32.964 1328-1680/? E/MediaPlayerService: Couldn't open fd for content://com.android.externalstorage.documents/document/primary%3Aiphone6.mp3
11-11 09:09:32.965 1611-3697/system_process E/MediaPlayer: Unable to create media player
11-11 09:09:32.965 1611-3697/system_process D/Ringtone: Problem opening; delegating to remote player
11-11 09:09:32.954 3293-3293/? W/Binder_2: type=1400 audit(0.0:34): avc: denied { read } for path="/storage/emulated/0/iphone6.mp3" dev="fuse" ino=23 scontext=u:r:system_server:s0 tcontext=u:object_r:fuse:s0 tclass=file permissive=0
请帮我解决这个问题。提前致谢
我已经搜索了如何获得android.permission.MANAGE_DOCUMENTS
权限。我收集的是它的安全级别为signature
,只有Android附带的应用程序才能获得该许可。
答案 0 :(得分:0)
请正确检查错误
在这里,我可以看到requires android.permission.MANAGE_DOCUMENTS or android.permission.MANAGE_DOCUMENTS
并且您还必须对这些权限使用运行时权限