当我尝试通过PhoneGap解析本地文件系统URI时,出现了这个错误:
java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaDocumentsProvider
我使用相机来访问照片库并获取此文件URI:
content://com.android.providers.media.documents/document/image%3A355
然后我尝试访问本地文件系统:
window.resolveLocalFileSystemURI(file_uri, function(a){console.log("success");}, function(b){console.log("fail");});
这就是我收到错误的地方:
02-18 10:13:14.546 app W/System.err﹕ java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaDocumentsProvider uri content://com.android.providers.media.documents/document/image:355 from pid=22659, uid=10098 requires android.permission.MANAGE_DOCUMENTS, or grantUriPermission()
02-18 10:13:14.546 app W/System.err﹕ at android.os.Parcel.readException(Parcel.java:1465)
02-18 10:13:14.546 app W/System.err﹕ at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
02-18 10:13:14.546 app W/System.err﹕ at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
02-18 10:13:14.546 app W/System.err﹕ at android.content.ContentProviderProxy.query(ContentProviderNative.java:413)
02-18 10:13:14.546 app W/System.err﹕ at android.content.ContentResolver.query(ContentResolver.java:461)
02-18 10:13:14.546 app W/System.err﹕ at android.content.ContentResolver.query(ContentResolver.java:404)
02-18 10:13:14.546 app W/System.err﹕ at android.app.Activity.managedQuery(Activity.java:1796)
02-18 10:13:14.546 app W/System.err﹕ at org.apache.cordova.file.FileUtils.resolveLocalFileSystemURI(FileUtils.java:263)
02-18 10:13:14.546 app W/System.err﹕ at org.apache.cordova.file.FileUtils.execute(FileUtils.java:150)
02-18 10:13:14.546 app W/System.err﹕ at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:65)
02-18 10:13:14.546 app W/System.err﹕ at org.apache.cordova.PluginManager.execHelper(PluginManager.java:229)
02-18 10:13:14.556 app W/System.err﹕ at org.apache.cordova.PluginManager.exec(PluginManager.java:214)
02-18 10:13:14.556 app W/System.err﹕ at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:53)
02-18 10:13:14.556 app W/System.err﹕ at com.android.org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
02-18 10:13:14.556 app W/System.err﹕ at com.android.org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:27)
02-18 10:13:14.556 app W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:102)
02-18 10:13:14.556 app W/System.err﹕ at android.os.Looper.loop(Looper.java:136)
02-18 10:13:14.556 app W/System.err﹕ at android.os.HandlerThread.run(HandlerThread.java:61)
顺便说一下:我在iOS上尝试了这种情况,没有问题。
AndroidManifest.xml:
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" android:windowSoftInputMode="adjustPan" package="app" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:debuggable="true" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:name="openApi" android:theme="@android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="image/*"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="audio/*" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />