1

I'm having the following error on a few of my users:

 Caused by: java.lang.SecurityException: Permission denied (missing INTERNET permission?) at java.net.InetAddress.lookupHostByName(InetAddress.java:418) at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) at java.net.InetAddress.getAllByName(InetAddress.java:214) at com.android.okhttp.internal.Dns$1.getAllByName(Dns.java:28) at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:216) at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:122) at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:292) at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255) at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206) at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345) at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89) at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:197) at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:254) at [my communication HttpUrlConnection request] ... 12 more Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname) at libcore.io.Posix.getaddrinfo(Native Method) at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:61) at java.net.InetAddress.lookupHostByName(InetAddress.java:405) ... 25 more Caused by: libcore.io.ErrnoException: getaddrinfo failed: EACCES (Permission denied) ... 28 more 

The app requires internet to do it's most basic function, I don't think a user have removed the permission using root or something like that.

Additionally, this error was sent to me with my own error reporting tool. I have made the upload with the registered error and at that moment the permission was available.

There is no restriction on device model of android version that has the error.

Example of a part of the manifest:

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

Any clue is appreciated,

Thanks in advance.

4
  • There is a same question"stackoverflow.com/questions/34163435/…" but there is no useful comment .so I have to ask again. Commented Jan 20, 2017 at 8:21
  • TKS, but that is not a same question. Commented Jan 20, 2017 at 8:29
  • Can you upload more of your manifest? Is the internet permission placed before your <application> tag in the manifest? Commented Jan 20, 2017 at 8:41
  • Also order matters if anyone needs to know stackoverflow.com/questions/25135595/… Commented Nov 7, 2017 at 15:54

2 Answers 2

2

this might help you

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
Sign up to request clarification or add additional context in comments.

Comments

0

I have this code which can help. This will ask only those permissions which are necessary for your applications

 public static boolean hasPermissions(Context context, String... permissions) { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context != null && permissions != null) { for (String permission : permissions) { if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) { return false; } } } return true; } 

add this code in ur onCreate

 int PERMISSION_ALL = 1; String[] PERMISSIONS = {Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_SMS, Manifest.permission.CAMERA}; if (!hasPermissions(this, PERMISSIONS)) { ActivityCompat.requestPermissions(this, PERMISSIONS, PERMISSION_ALL); } 

3 Comments

Once you add these codes in your onCreate it will ask the permission only once and then you dont need to worry about adding permissions in manifest
I have add this in the code. but it is still have this bug with a very small change
@titoFlying i think the main problem is in the device. The only last way i think is to go to Settings-> Apps->Permission and enable it. Else the above code has worked for every application (including the internet permissions) that i have developed. Please Do let me know what kind of issue you are facing with. Thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.