权限被拒绝(缺INTERNET权限?):但是,许可给权限、被拒、许可、INTERNET

2023-09-05 02:34:15 作者:网游名字

我试图调用的HttpClient和响应是权限被拒绝(缺INTERNET权限?)。在Android中的正常的浏览器,我可以没有问题打开URL。

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?)

在我的清单的权限集:

<?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>

推荐答案

你有没有试着给许可上面的应用程序标签?

Did you try giving permission above the application tag?

您应该采取的为了在标签定义在照顾的Manifest.xml。

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

请参阅structure的清单。

编辑:

<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>

详细信息:

订单定义的标签清单

权限 应用程序 接收器,服务,元数据