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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
titoFlying
  • 41
  • 1
  • 5
  • There is a same question"http://stackoverflow.com/questions/34163435/httpurlconnection-request-error-missing-internet-permission-when-the-permission" but there is no useful comment .so I have to ask again. – titoFlying Jan 20 '17 at 08:21
  • TKS, but that is not a same question. – titoFlying Jan 20 '17 at 08:29
  • Can you upload more of your manifest? Is the internet permission placed before your tag in the manifest? – mcarlin Jan 20 '17 at 08:41
  • Also order matters if anyone needs to know https://stackoverflow.com/questions/25135595/permission-denied-missing-internet-permission-but-permission-is-given – Nabin Nov 07 '17 at 15:54

2 Answers2

1

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" />
Vaibhav Joshi
  • 145
  • 1
  • 5
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);
    }
Vaibhav Joshi
  • 145
  • 1
  • 5
  • 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** – Vaibhav Joshi Jan 20 '17 at 10:18
  • I have add this in the code. but it is still have this bug with a very small change – titoFlying Jan 21 '17 at 03:18
  • @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 – Vaibhav Joshi Jan 21 '17 at 11:55