【问题标题】:PhoneGap Build not including permissions for android or platforms other than browserPhoneGap Build 不包括 android 或浏览器以外平台的权限
【发布时间】:2017-07-24 00:12:40
【问题描述】:

我有一个 phonegap 应用程序在通过官方 phonegap 应用程序打开/加载时工作正常(执行 ajax http 请求等)。

但是当我上传和构建应用程序并从 build.phonegap 网站下载 apk 时,外部 http 请求都不起作用。 我还注意到,由于我在 android 上,因此在安装或服务请求(6.0+)时没有为应用程序请求任何权限,并且在应用程序管理器中查看应用程序时,它被列为不使用权限。所以我假设在没有互联网许可的情况下,我的应用程序不被允许连接 http 请求。

所以我的问题是如何获得它来请求我需要的互联网等权限?我认为 phonegap 应该默认请求互联网和其他一些东西,但似乎根本没有请求它们。

不过,我还要注意,在应用程序中,platforms 文件夹中列出的唯一平台是浏览器,因此我没有 platform->android->config.xml 来进行任何潜在的编辑,正如我在这个网站上有几个地方,但我的项目根 config.xml 看起来像这样,我的潜在敏感信息被 ******* 替换。

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.******.mainapp" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
    <name>********</name>
    <description>
        **********
    </description>
    <author email="*******" href="********">
        ***********
    </author>
    <content src="index.html" />
    <access origin="http://*******.com/*" />
    <access origin="http://admin.*******.com/*" />
    <access origin="*" />
    <preference name="Orientation" value="portrait" />
</widget>

编辑:任何潜在的帮助、建议或建议都会有所帮助和赞赏,因为我整天都在尝试解决这个问题,但无济于事

EDIT2:应用中的示例请求

var http = new XMLHttpRequest();
var url = "http://www.********.com/functions/*******.php";
http.open("GET", url, true);
http.send();        
http.onreadystatechange = function() {
    if (http.readyState == 4) {
        if (http.responseText.indexOf("success") >= 0) {
            var data = http.responseText.split(" - ")[1];
            populate(data);
        } else {
            alert(http.responseText);
        }
        loadingScreen.style.display = "none";
    }
};

【问题讨论】:

  • 在我的请求中使用 https 协议时遇到了类似的问题。你只使用 http ???
  • 目前所有连接都是http,因为我还没有在我的服务器上安装ssl
  • 我在上面进行了编辑以包含我的一个 http 请求的示例
  • 在你的 index.html 中,你有 ssl.gstatic.com 'unsafe-eval '; style-src 'self' 'unsafe-inline'; media-src *; connect-src myserver.mydomain.com"> 启用???
  • 我在您的 config.xml 文件中没有看到白名单插件。尝试添加它(cordova-plugin-whitelist)。见cordova.apache.org/docs/en/latest/reference/…

标签: android cordova phonegap-build phonegap-desktop-app


【解决方案1】:

最初来自 Kerri Shotts 的回答解决了我的问题,

config.xml 需要包含该行

<plugin name="cordova-plugin-whitelist" source="npm" spec="~1.2.1" />

添加后,一切都按预期工作

【讨论】:

    猜你喜欢
    • 2013-03-10
    • 2014-04-08
    • 1970-01-01
    • 2012-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多