trying to do a simple communication test between my PC and phone (currently testing with emulator)
I have created a c# Rest service that works ok
URL: http://192.168.1.100:8000/REST/client
Result:
TEST STRING!
I have a Call function in my android app that looks like this:
public void call()
{
String URL = "http://192.168.1.100:8000/REST/client";
EditText txt = (EditText) findViewById(R.id.Textbox);
String Result = "";
Toast.makeText(Helloworld.this, "STARTING", Toast.LENGTH_SHORT);
HttpClient hc = new DefaultHttpClient();
HttpGet request = new HttpGet(URL);
ResponseHandler<String> handler = new BasicResponseHandler();
try{
Result = hc.execute(request,handler);
}
catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
txt.setText(Result);
Toast.makeText(Helloworld.this, Result, Toast.LENGTH_SHORT);
hc.getConnectionManager().shutdown();
}
i call this from a button,
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
EditText txt = (EditText) findViewById(R.id.Textbox);
txt.setText("calling!", TextView.BufferType.EDITABLE );
call();
}
});
few problems, with this code as is, if i run it i dont see any Toast msgs and the textbox isnt updated. if however i remove the call() from the onclick, the textbox is updated. it seems as though the call is hanging, but even if it was, wouldnt i see the text updated anyways?
Assuming that it can reach your service etc, you should be doing it with AsyncTasks and calling invalidate to make sure the updates are shown on the screen. Also, you have to call
.show()onmakeText(). I haven’t tested this but it should be the right idea.Also, you need to have the proper permissions set up for your app. Include the following line in your manifest xml: