Search code examples
androidcordovaphonegap-buildphonegap-desktop-app

PhoneGap Build not including permissions for android or platforms other than browser


I have a phonegap application that works fine (ajax http requests are executed, etc) when opened/loaded through the official phonegap app.

But when I upload and build the application and download the apk from the build.phonegap website, none of the external http requests work. I also noticed that since I am on android that no permissions were ever requested for the application on install or on service request(6.0+) and when looking at the application in the app manager it is listed as using no permissions. So I am assuming that without the internet permission my app is not being allowed to connect for http requests.

So my question is how do I get it to request the permissions for internet, etc that I need? I thought phonegap was supposed to default request things like internet and a few others but it seems like they are not being requested at all.

I will also note however that in the app the only platform listed in the platforms folder is browser so I do not have a platforms->android->config.xml to do any potential edits in as I have seen suggested in a couple places on this site but my project root config.xml looks like this with my potentially sensitive info replaced with *******'s.

<?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>

EDIT: Any potential help, suggestions, or advice would be helpful and appreciated as I have been trying to solve this problem all day to no avail

EDIT2: Example request in the app

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";
    }
};

Solution

  • Answer originally from Kerri Shotts solved my problem,

    config.xml needed to include the line

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

    Once this is added everything works as expected