在我的應用程序API級別targetSdkVersion 23.我已經添加權限,如下所示:Android不有權閱讀內容://媒體/外部/音頻/媒體
<?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異常:102的Uid 09無權以URI 0 @內容://媒體/外部/音頻/媒體
但烏里allsongsuri = MediaStore.Audio.Media.INTERNAL_CONTENT_URI;
作品。 Uri的例外allsongsuri = MediaStore.Audio.Media.INTERNAL_CONTENT_URI;
請注意,相同的代碼適用於較舊的設備的Android 4.但它發生在Android 6.我認爲一些新的東西是爲Android 6添加權限。請如何解決這個問題。