-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainActivity.java
57 lines (45 loc) · 1.92 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.iot.climateedge.connection;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
public class MainActivity extends AppCompatActivity {
Button button;
TextView textView;
String server_url = "http://129.31.178.216/greetings.php"; //change url and php filename here
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button)findViewById(R.id.bn);
textView = (TextView)findViewById(R.id.txt);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
final RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);
StringRequest stringRequest = new StringRequest(Request.Method.POST, server_url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
textView.setText(response);
requestQueue.stop();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
textView.setText("Something went wrong...");
error.printStackTrace();
requestQueue.stop();
}
});
requestQueue.add(stringRequest);
}
});
}
}