I am new to Java and Android development and trying to create a simple application that needs to contact a web server and add some data to the database using http get.
When I make a call using a web browser on my computer, it works fine. However, when I make a call launching the application in the Android emulator, the data is not added.
I have added Internet permission to the application manifest. Logcat does not report any problems.
Can someone help me figure out what happened?
Here is the source code:
package com.example.httptest; import java.io.IOException; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.TextView; public class HttpTestActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView tv = new TextView(this); setContentView(tv); try { URL url = new URL("http://www.mysite.se/index.asp?data=99"); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.disconnect(); tv.setText("Hello!"); } catch (MalformedURLException ex) { Log.e("httptest",Log.getStackTraceString(ex)); } catch (IOException ex) { Log.e("httptest",Log.getStackTraceString(ex)); } } }
java android-emulator android-internet
user1119112 Dec 28 '11 at 10:47 2011-12-28 10:47
source share