Hans
Hans

Reputation: 231

Why is the internet not working on emulator but working on real device? (Android Studio)

NOTE: This question is not intended to find a solution for a problem. It is directed towards finding information of why is the problem happening.

I created an app, which is supposed to access the internet. but I didn't add the line

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

to the manifest file, which should lead to an app unable to access the internet. It is not able to access the internet(obviously), in the emulator. However, in my phone, it works perfectly fine (i.e. I can access the Internet through the app!!!).

Why does this happen?

Upvotes: 2

Views: 1941

Answers (2)

RadiBarq
RadiBarq

Reputation: 31

if you run the emulator first and then you got connected to the internet the emulator and your app will not have an internet connection so try closing and opening the emulator again.

Upvotes: 0

Ugurcan Yildirim
Ugurcan Yildirim

Reputation: 6132

If you are creating an Intent and open url in Chrome or other app than yours, then your app won't need the INTERNET permission. However, if your app has a WebView as a UI component and you try to load url on this WebView, you need that permission.

To avoid loadUrl(...) opening browser problem, add this line before calling loadUrl(...):

myWebView.setWebViewClient(new WebViewClient());

Upvotes: 2

Related Questions