ページからデータを受け取る必要があるAndroidアプリケーションを作成します。http://example.com/get.php?id=1このために私は次のメソッドを使用します。 アン:Webページ(Android)から情報を取得するにはどうすればいいですか?
private String getData()
{
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext(); // !!! application stops here
HttpGet httpGet = new HttpGet("http://example.com/get.php?id=1");
HttpResponse response = null;
try {
response = httpClient.execute(httpGet, localContext);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String result = "";
BufferedReader reader = null;
try {
reader = new BufferedReader(
new InputStreamReader(
response.getEntity().getContent()
)
);
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String line = null;
try {
while ((line = reader.readLine()) != null){
result += line + "\n";
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Now you have the whole HTML loaded on the result variable
return result;
}
を私はまた、AndroidManifest.xmlを
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.repetitor_ent_free"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
問題は、私は、デバイス上でアプリケーションを実行すると、私はエラーを取得するということであるに権限を追加予期しないアプリケーションMyApp(プロセスcom.android.myapp)を停止します。もう一度お試しください。これを使用する
ログインしてみてください。ネットワークがメインスレッドで使用されている場合は、エラーが表示されます(sdk api> 5)。 – m039
Logcat出力をポストしてデバッグを容易にします。 – Thommy
logcatを確認してください。あなたは例外を見つけて、ここに投稿します。 –