简体   繁体   English

无法通过代码为Android M设置铃声

[英]Unable to set ringtone through code for Android M

I am developing an application that will randomly set a ringtone from a list of tones user has already selected. 我正在开发一个应用程序,它将从用户已经选择的音调列表中随机设置铃声。

While my code works for Android N and above, I am facing problems with Android M and below. 虽然我的代码适用于Android N及更高版本,但我遇到了Android M及更低版本的问题。 I've search a lot for the solution. 我已经寻找了很多解决方案。 But could not find any. 但是找不到任何东西。

Here is my code snippet that is setting the ringtone. 这是设置铃声的代码段。

RingtoneManager.setActualDefaultRingtoneUri(getApplicationContext(),
                                RingtoneManager.TYPE_RINGTONE,
                                uri);

Here is the link to entire file . 这是整个文件链接

Here is my manifest file. 这是我的清单文件。

<?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>

Here is the error log that is generated while the application is running 这是应用程序运行时生成的错误日志

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

Please help me solve this issue. 请帮我解决这个问题。 Thanks in advance 提前致谢

I've searched for how to get android.permission.MANAGE_DOCUMENTS permission. 我已经搜索了如何获取android.permission.MANAGE_DOCUMENTS权限。 What I have gathered is it's security level is of signature and only applications that come with android can have that permission. 我收集到的是它的安全级别是signature ,只有android随附的应用程序才能具有该权限。

请正确检查您的错误在这里我可以看到requires android.permission.MANAGE_DOCUMENTS or android.permission.MANAGE_DOCUMENTS ,并且您还必须使用运行时权限来获取这些权限

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM