权限被拒绝(缺lessINTERNET权限?):但是有权限

我试图调用一个httpClient和响应是“权限被拒绝(缺less互联网权限?)”。 在Android的正常浏览器中,我可以打开url,而不会出现任何问题。

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(); } 

catch日志告诉我错误:

 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> 

你有没有尝试给应用程序标签上面的权限

您应该注意Manifest.xml中定义标签的顺序

参见Manifest的结构 。

编辑:

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

细节:

Manifest中定义选项卡的顺序:

  1. 权限
  2. 应用
  3. 接收者,服务,元数据

权限必须超出应用程序标记。 所以你需要在外面移动你的权限

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

阅读清单文件的结构 。 语法是

 <manifest> <uses-permission /> <application> .... </application> </manifest> 

Permissions不应该在Application Tag ..你必须把它作为一个Manifest的孩子..

将您的用户权限标签放在应用程序标签上方。 链接: http : //developer.android.com/guide/topics/manifest/uses-feature-element.html

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="..." > <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" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <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> 

 <uses-permission/> <application/> 

错误

 <application> <uses-permission/> <application/> 

试试这个你给权限正确,但是权限必须在应用标签之外维护标签的顺序

  <manifest> <uses-permission /> <application> .... </application> <receiver> </receiver> <service> </service> </manifest> your code is like this way <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="..." > <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"/> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <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> </manifest>