http connectionjavajava.lang.SecurityException中的android错误:权限被拒绝(缺少INTERNET权限?)

时间:2013-09-04 21:41:22

标签: android permissions connection

我是android开发的新手,我需要帮助。 我尝试在我的应用中连接https://www.google.cz/,但它给了我一个错误:

http connectionjavajava.lang.SecurityException出错:Permission denied(缺少INTERNET权限?)

Java代码:

    public class SuplAct extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {

    try{    
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_supl);

        StrictMode.ThreadPolicy policy = new
        StrictMode.ThreadPolicy.Builder()
        .permitAll().build();
        StrictMode.setThreadPolicy(policy);

        TextView MyTextview = (TextView)findViewById(R.id.hello_world);

        try{
        HttpClient  httpclient = new DefaultHttpClient() ;
        HttpPost httppost = new HttpPost("https://www.google.cz/");
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        InputStream webs = entity.getContent();
        try{
            BufferedReader reader = new BufferedReader(new InputStreamReader (webs,"iso-8859-1"),8); 
            MyTextview.setText(reader.readLine());
            webs.close();

        }catch(Exception e){Log.e("log_tag","Error converting result"+e.toString() );}
    }catch(Exception e){Log.e("log_tag","Error in http connection"+e.toString() );}
    }catch(Exception e){Log.e("ERROR","ERROR in the code"+e.toString() );
    e.printStackTrace();}   
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.supl, menu);
        return true;
    }

}

清单:

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

    <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="17" />
    <uses-permission android:name = "android.premission.INTERNET"></uses-permission>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="cz.bakalari.bakalari.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="cz.bakalari.bakalari.RozvrhAct"
            android:screenOrientation="landscape"
            android:label="@string/title_activity_rozvrh" >
        </activity>
        <activity
            android:name="cz.bakalari.bakalari.KlasifikaceAct"
            android:label="@string/title_activity_klasifikace" >
        </activity>
        <activity

            android:name="cz.bakalari.bakalari.SuplAct"
            android:label="@string/title_activity_supl" >
        </activity>
    </application>

</manifest>

1 个答案:

答案 0 :(得分:1)

检查您的权限语法:

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

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