2

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?

Mithun Sarker Shuvro
  • 3,479
  • 6
  • 28
  • 54
Hans
  • 165
  • 1
  • 10
  • What do you exactly mean by "accessing the Internet through the app"? – Ugurcan Yildirim Aug 17 '16 at 16:43
  • @UgurcanYildirim Thanks for the quick reply. The app has a WebView, and I can open an internet website from it, but I shouldn't be able to (I haven't add the permission in the manifest). – Hans Aug 17 '16 at 16:44
  • Yeah, actually it shouldn't be able to. Have you tried (cleaned/rebuilt the project) couple of times just to be sure that IDE successfully built an APK that contains manifest without Internet permission? – Ugurcan Yildirim Aug 17 '16 at 16:51
  • You some time used this permission and remove later ? The permission is granted when you install the app, when you run through the Android Studio, the app don't need newer permissions, so the user will not be prompted during the install. Try Uninstall the APP and install again without the permission (Or find the App info in the Configurations of the device and check the permissions) – Lucas Queiroz Ribeiro Aug 17 '16 at 16:52
  • @LucasQueirozRibeiro Mmmm, I am going to be honest here: I am learning to create apps. This is the first time I try to access the internet from an app, I have NEVER ever, not in this nor other app, given such a permission. – Hans Aug 17 '16 at 16:54
  • In the first time you have installed this APP the manifest don't have the permission ? What's the Android Version ? – Lucas Queiroz Ribeiro Aug 17 '16 at 16:58
  • @LucasQueirozRibeiro The manifest has never been altered, never given such a permission. I have 5.1.1. I uninstalled the app and currently making a test as adviced by Ugurcan Yildirim. – Hans Aug 17 '16 at 16:59
  • @UgurcanYildirim Did as adviced, cleaned and rebuilt. Still the same. – Hans Aug 17 '16 at 17:02
  • That's strange, i know that in Android 6+ (Marshmallow) the internet permission is not required (but is recommended), so, all APP have internet permission. – Lucas Queiroz Ribeiro Aug 17 '16 at 17:04
  • What Url are you trying to access ? – Lucas Queiroz Ribeiro Aug 17 '16 at 17:06
  • @UgurcanYildirim Now I see what your first question was about. Actually I am not able to access "through" the app. The app opens another app I have installed on my phone. I think I got confused, in the emulator, the app is unable to "open" other apps in order to access the internet. Am I getting it right now? and, anyway, is this a normal behavior? – Hans Aug 17 '16 at 17:06
  • @LucasQueirozRibeiro have a look at my last comment, please (www.google.com is the answer to your last question). – Hans Aug 17 '16 at 17:07
  • 1
    @Hans see my answer. – Ugurcan Yildirim Aug 17 '16 at 17:25
  • Yes, may be, i figured you are using the WebView component, if you use an Intent, the other app may have the permission not yours – Lucas Queiroz Ribeiro Aug 17 '16 at 17:34

2 Answers2

1

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());
Ugurcan Yildirim
  • 4,820
  • 2
  • 33
  • 65
0

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.

RadiBarq
  • 31
  • 3