Ionic run android works BUT apk does not access internet


#14

I was missing the whitelist plugin:

ionic plugin add https://github.com/apache/cordova-plugin-whitelist.git

After adding everything worked as aspected


Ionic mobile app $http fails to connect. But in browser it works fine
#15

I have a similar problem, the browser works perfectly but when installing the device or emulate simply does not perform the request, checked my files and my AndroidManifest.xml config.xml file and the information below respectively list the permissions:

AndroidManifest.xml

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

and config.xml

<access origin="*"/>

someone help me know I’m desperate to deliver the project and this is delaying me more than usual.


#16

If you updated recently (running cordova 5.0), my guess would be the cordova-plugin-whitelist needs to be installed. After installing, add this to config.xml to allow all http/s requests :
allow-intent href="http:///"
allow-intent href=“https:///


#17

That was the problem install the plugin and it worked perfectly! :smile:


#18

Same for me, thanks a lot!


#19

Not work for me…
add this to config.xml :

   <access origin="*"/>                    
   <allow-intent href="*" />
   <allow-navigation href="*" />

Any ideas ? Please help!
Not work only release build, debug build work fine.
Whitelist plugin and 5.0.0 cordova installed.


Cordova/Ionic CLI hooks for modifying AndroidManifest.xml or IOS PList file?
#20

Next guess (since I don’t know ur architecture) is to look at server-side and “CORS”. If ur running node with express backend, here’s a sample whitelist/cors “configuration”:
var whitelist = [‘http://localhost:8100’, ‘http://localhost:9000’, ‘http://localhost:8080’];
var corsOptions = {
origin: function(origin, callback){
var originIsWhitelisted = whitelist.indexOf(origin) !== -1;
callback(null, originIsWhitelisted);
}
};
app.use(cors(corsOptions));


#21

Wow, thanks for fast reply, may i send you example with jquery requests to my api ? where can i send it (i think i just drop it here)?
i dont have acces to server side its works on java jwt and they add all headers needed for cors, and its cant be cors problem becaues debug version work well on device, only after cordova build --release android its stop working…
Device Lenovo P780, android version 4.4

Ther is my test www folder: https://drive.google.com/open?id=0B869Sv33xwGWNWdaUkRIY0dPSTg&authuser=0


#22

Ok like kkraus said its “Worked over http. Did not work over https” so how fix that? how set certifcate ?


#23

It’s very simple to fix the no internet issue… run the following command in your terminal in the project folder…

cordova plugin add cordova-plugin-whitelist

Also make sure you have the following in your Android manifest…

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

#24

You are right! i had same issue and it was solved using your solution.


#25

Guys Thank you very much for the help ,finally with the help of this topic my similar issue was solved.

Thanks


#27

Thank you so much for this!! :slight_smile:


#28

My issue was due to an incorrect intermediate certificate.

Since it seems many different problems serve up similar symptoms, you can quickly rule out or diagnose the server ssl certificate issue by entering the server name at https://www.sslshopper.com. It will flag problems with your server cert. If it returns a properly set up certificate you can rule out that problem and move on to the next…


#29

If it’s can help someone,

I had the same problem, I solved it by checking the javascript console of the ionic server browser page.
I read the error and understand quickly : The app try to connect to my localhost with a new and different port.

I just add a new allowing thing with the good number in my PHP webservice file :
header(‘Access-Control-Allow-Origin: http://localhost:8383’);
header(‘Access-Control-Allow-Origin: http://localhost:8100’); // NEW ASKED PORT * added *
header(“Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization”);

Good luck !


#30

To load external images and use the Facebook API I did the following:

  1. in the project config.xml remove the line

     <preference name="android-minSdkVersion" value="16"/>
    
  2. Install the whitelist plugin

     ionic plugin add https://github.com/apache/cordova-plugin-whitelist.git
    
  3. in platforms/android/AndroidManifest.xml

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

#31

Hi kkraus, I have the similar issue. Works over http but fails over https. I am new these certificates and stuff. can you please tell me how to go forward and provide me steps to solve this issue.


#32

See my comment on how to resolve this:

You can test your certificate with online tools and then you have to resolve any found (chain) issues.


#33

Yes, this is the correct answer, It works for me after many hours of research, thank you very much !!


#34

Adding cordova whitelist component solved it for me.