0

I have been testing my app using ionic serve while developing and everything is working fine. I am now trying to export the apk using ionic build android, then storing the file 'android-debug.apk' on my web server and downloading it via a phone's browser and installing it to test it in the real world.

The app installs OK, but won't let me make any $http requests. I have installed the plugin cordova-plugin-whitelist, and also added the following to my config.xml file:

 <plugin name="cordova-plugin-whitelist" spec="1" /> <access origin="*" /> <allow-navigation href="*" /> <allow-intent href="*" /> <allow-intent href="http://*/*" /> <allow-intent href="https://*/*" /> <allow-intent href="tel:*" /> <allow-intent href="sms:*" /> <allow-intent href="mailto:*" /> <allow-intent href="geo:*" /> <platform name="android"> <allow-intent href="market:*" /> </platform> <platform name="ios"> <allow-intent href="itms:*" /> <allow-intent href="itms-apps:*" /> </platform> 

As well as that, I have added this into my main index.html file:

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"> 

Can someone tell me why the requests are still failing please?

I have tested on 2 different servers, both have CORS enabled and this has been verified using Postman.

Thanks for any help

Edit:

My $http request looks like this:

$http.get('http://url.com/request').then(function(res) { console.log('success'); console.log(res); }, function(res) { console.log('error'); console.log(res); }); 

After enabling remote chrome debugging, I get an error alert, following by an object which has:

data: null, status: 0, statusText: "" 
7
  • You can inspect the hybrid app using chrome and it can show you the error.connect your phone to your system and inspect the app. Commented Aug 11, 2015 at 8:43
  • I just tried that and the error I get is: POST: http//url.com net::ERR_CACHE_MISS...doesn't give much more information though Commented Aug 11, 2015 at 9:00
  • In the network tab, the request says (failed) xhr Commented Aug 11, 2015 at 9:01
  • copy the url and try to run it through postman in your system. see if you can get the response. Commented Aug 11, 2015 at 9:06
  • This is possibly related: stackoverflow.com/questions/25664146/… Commented Aug 11, 2015 at 9:14

1 Answer 1

2

Looks like I needed to add:

<uses-permission android:name="android.permission.INTERNET" /> 

into platforms/android/AndroidManifest.xml. Working OK now!

Sign up to request clarification or add additional context in comments.

2 Comments

I have the permission in the AndroidManifest.xml but still failing. Any other pointers? its been 2 days but still not able to resolve the issue
This happened to me after I upgrading (/generally messing about with) cordova versions - maybe that declaration was added in Cordova 7? Doing "cordova platform remove android" then "cordova platform add android" fixed it properly for me...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.