Hans Hans - 1 year ago 51
Android Question

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?

Answer Source

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());