2

サーバーから XML を取得するために HttpURLConnection を実験しようとしています。これは私が使用しているコードです:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    String myConn = this.getString(R.string.myConnection);
    HttpURLConnection httpConnection = null;
    InputStream in = null;
    try {
        URL mySite = new URL(myConn);
        URLConnection connection = mySite.openConnection();
        TextView tv = (TextView)this.findViewById(R.id.myTextView);
        httpConnection = (HttpURLConnection)connection;         

            in = httpConnection.getInputStream();

            String myString = convertStreamToString(in);
            tv.setText(myString);           

    } catch (IOException ex) {} catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    finally {
        httpConnection.disconnect();
        try {
            in.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

エミュレーターでは、このコードは機能し、TextView でストリームを確認できます...

私のデバイスでは何も見えません (3g 接続)。

私は何か見落としてますか?

ありがとう

4

1 に答える 1