gpt4 book ai didi

xml - Android无权读取content://media/external/audio/media

转载 作者:行者123 更新时间:2023-12-02 23:44:28 27 4
gpt4 key购买 nike

在我的应用程序API级别targetSdkVersion 23中,我添加了以下权限:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.mymetaextractor" >

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MetaExtractActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

当我尝试执行以下命令时:
    String[] STAR = {"*"};
Uri allsongsuri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
// Uri allsongsuri = MediaStore.Audio.Media.INTERNAL_CONTENT_URI;
String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";
Cursor cursor = null;


try {

this.grantUriPermission("my.mymetaextractor",
allsongsuri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
Intent.FLAG_GRANT_READ_URI_PERMISSION);
cursor = managedQuery(allsongsuri, STAR, selection, null,
null);
} catch (Exception e) {
String msg = e.getMessage();
Log.i("tag", "wait");
}

我收到 异​​常:

java.lang.SecurityException: Uid 10209 does not have permission to uri 0 @ content://media/external/audio/media



但是Uri allsongsuri = MediaStore.Audio.Media.INTERNAL_CONTENT_URI;有效。 Uri allsongsuri = MediaStore.Audio.Media.INTERNAL_CONTENT_URI;的异常(exception)

请注意,相同的代码在较旧的设备android 4中也能很好地工作。但是对于android 6来说,它确实发生了。请如何解决此问题。

最佳答案

您需要在运行时不仅在 list 中要求此许可权:permissions

如果(ContextCompat.checkSelfPermission(this,“android.permission.WRITE_EXTERNAL_STORAGE”)!= PackageManager.PERMISSION_GRANTED)
requestPermissions(new String [] {“android.permission.READ_PHONE_STATE”},0);

关于xml - Android无权读取content://media/external/audio/media,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33367571/

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