如何解决权限被拒绝可能缺少互联网权限?

时间:2012-10-16 19:48:30

标签: android android-manifest android-permissions

我正在使用Netbeans7.2并输入了uses-permission但是我有这个错误Java.net.Socket例外互联网被拒绝(可能缺少互联网权限) 我的AndroidManifest文件就像这样

  <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="importacao.dados"
          android:versionCode="1"
          android:versionName="1.0">
        <application android:label="@string/app_name" >
            <activity android:name="importacao"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                    <uses-permission android:name="android.permission.INTERNET" /> 
                </intent-filter>
            </activity>
        </application>
    </manifest> 

//按钮

cliente.setOnClickListener(new  Button.OnClickListener(){
    public void onClick(View view){
        InputStream is = null;
         ArrayList namevaluePairs = new ArrayList();
        List r = new ArrayList();
    try{
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost;
            httppost = new HttpPost("http://localhost/cliente.php");
        httppost.setEntity(new UrlEncodedFormEntity(namevaluePairs));
        HttpResponse response;
            response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();
    }
    catch(Exception e)
    {
        Toast.makeText(getBaseContext(),e.toString(),Toast.LENGTH_LONG).show();
    }
    try{
    BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"));
     StringBuilder sb = new StringBuilder();
     String line = null;
      while((line=reader.readLine()) != null)
     {
      //   
     }}
    catch(Exception e)
    {
       Log.e("Erro",e.toString());
    }}});

1 个答案:

答案 0 :(得分:6)

将您的uses-permission标记移动到应用程序标记之外。您还可能需要为android.permission.ACCESS_NETWORK_STATE添加一个uses-permission,不确定netbeans是如何工作的。

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

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

        <application android:label="@string/app_name" >