私はアンドロイド開発の初心者で、助けが必要です。アプリでhttps://www.google.cz/に接続しようとしましたが、エラーが発生しました:
http 接続のエラーjavajava.lang.SecurityException: 権限が拒否されました (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>