Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission denied (missing INTERNET permission?): But permission is given

Tags:

I'm trying to call a httpClient and the response is "Permission denied (missing INTERNET permission?)". In the normal browser of Android I can open the URL without problems.

 public static String getHttpResponse(URI uri) {
    StringBuilder response = new StringBuilder();
    try {

        HttpGet get = new HttpGet();
        get.setURI(uri);
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpResponse httpResponse = httpClient.execute(get);

        if (httpResponse.getStatusLine().getStatusCode() == 200) {
            Log.d("demo", "HTTP Get succeeded");

            HttpEntity messageEntity = httpResponse.getEntity();
            InputStream is = messageEntity.getContent();
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String line;
            while ((line = br.readLine()) != null) {
                response.append(line);
            }
        }
    } catch (Exception e) {
        Log.e("demo", e.getMessage());
    }
    Log.d("demo", "Done with HTTP getting");
    return response.toString();
}

The catch log tell me the error:

java.lang.SecurityException: Permission denied (missing INTERNET permission?)
libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
Permission denied (missing INTERNET permission?)

In my Manifest is the permission set:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="..." >

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <uses-feature android:name="android.hardware.camera" android:required="true" />

    <activity
        android:name=".main"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>


</application>

like image 431
user1878413 Avatar asked Aug 05 '14 09:08

user1878413


People also ask

Which of these manifest permissions are required for connecting the app to the Internet?

So yeah, you need the internet permission to access the internet. Even the basic docs on connecting to the internet also state that the internet permission is required.

How do I get permission denied on Android?

On your phone, open the Settings app. Permission manager. Tap a permission type. If you allowed or denied permission to any apps, you'll find them here.


2 Answers

Did you try giving permission above the application tag?

You should take care of order in which tags are defined in Manifest.xml.

See structure of Manifest.

Edited:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    ...>
</application>

Details:

Order of defining tabs in Manifest:

  1. Permissions
  2. Applications
  3. Receiver, Service, Metadata
like image 169
Nabin Avatar answered Oct 14 '22 23:10

Nabin


Permissions must be outside of application tag. So you need to move your permissions outside

<uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    ... >
</application>

Read about Structure of the Manifest File. The syntax is

<manifest>

    <uses-permission />

    <application>
        ....
    </application>

</manifest>
like image 41
Pankaj Kumar Avatar answered Oct 14 '22 22:10

Pankaj Kumar