【问题标题】:How to grant URI permission in PhoneGap build app?如何在 PhoneGap 构建应用程序中授予 URI 权限?
【发布时间】:2016-02-05 20:19:17
【问题描述】:

环境:这是我开发过的唯一跨平台应用程序。我没有建造它。它大约5岁。适用对象:Android 4.4及以上,iOS不限。我在 Mac 上开发,使用 Phonegap Build- 特别是 3.7.0。我在我的 Android 模拟器 - API 23 和 19 上收到此错误。

我正在尝试访问 imageURI 以检查文件大小。我的FileTransfer 限制约为 10 mb。这是我的代码:

resolveLocalFileSystemURI(this.pageContainer.items.items[0].imageURI, function(fileEntry){
                fileEntry.file(function(fileObj){
                     if (maxSize <= fileObj.size){
                          Ext.Msg.alert("Error", "Chosen image is too large. Submit a different image.");   
                          return;
                      }
                      else {
                          Ext.Msg.alert("You are here:", "file size accepted "+ fileObj.size);
                       }
                  })
            })

问题是它无法通过resolveLocalFileSystemURI。 adb 日志说:

E DatabaseUtils: java.lang.SecurityException: Permission Denial: reading
com.android.externalstorage.ExternalStorageProvider uri
content://com.android.externalstorage.documents/document/1A03-
3B0B%3ADCIM/Camera/elevation.jpg from pid=2921, uid=10080 requires
android.permission.MANAGE_DOCUMENTS, or grantUriPermission()

我知道您可以将此权限添加到 AndroidManifest,然后从那里开始,但我实际上只是使用 PhoneGap build 3.7.0。我必须编辑config.xml,它目前正在使用这些设置:

<plugin name="org.apache.cordova.camera" source="pgb" spec="0.3.2" />
<plugin name="org.apache.cordova.device" source="pgb" spec="0.2.12" />
<plugin name="org.apache.cordova.file" source="pgb" spec="1.3.3" />
<plugin name="org.apache.cordova.file-transfer" source="pgb" spec="0.5.0" />
<plugin name="org.apache.cordova.geolocation" source="pgb" spec="0.3.10" />
<plugin name="org.apache.cordova.network-information" source="pgb" 
spec="0.2.12" />

<preference name="phonegap-version" value="3.7.0" />
<preference name="android-minSdkVersion" value="19" />
<preference name="orientation"      value="portrait" />
<preference name="target-device"    value="universal" />
<preference name="fullscreen"       value="true" />
<preference name="prerendered-icon" value="false" />

<feature name="http://api.phonegap.com/1.0/network" />
<feature name="http://api.phonegap.com/1.0/camera" />
<feature name="http://api.phonegap.com/1.0/geolocation" />
<feature name="http://api.phonegap.com/1.0/media" />
<feature name="http://api.phonegap.com/1.0/contacts" />
<feature name="http://api.phonegap.com/1.0/file" />
<feature name="http://api.phonegap.com/1.0/device" />

以前,我没有包含 &lt;feature&gt;,但为了尝试修复,将其添加到我的 config.xml 中,这导致行为没有变化。我需要向我的config.xml 添加什么内容才能与 MANAGE_DOCUMENTS 一样?

【问题讨论】:

  • 在您的帖子中回答以下问题。因为这似乎是你关于这个主题的第一篇文章。这是您的第一个混合应用程序吗?您的目标平台及其目标版本是什么?安卓4、5、6? iOS 7、8、9?你在什么平台上开发?视窗,MacOS?你在使用CLI, SDK or Build 吗?请不要假设答案,请阅读链接。一旦您在帖子中回答了问题,请在 cmets 中回复,以便我知道您已在帖子中添加信息。
  • 我已经添加了信息。

标签: android cordova phonegap-build


【解决方案1】:

解决方案是将我的 PhoneGap Build 版本升级到 cli-5.2.0(我敢肯定还有其他版本)。当我的 Android 目标为 19+ 时,我的构建版本太旧,无法支持授予 Android 对文件的访问权限。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    相关资源
    最近更新 更多