<uses-permission android:name="android.permission.INTERNET"/>
build.gradle
compile 'com.google.code.gson:gson:2.5'
compile 'com.github.bumptech.glide:volley-integration:1.3.1'
mt_rand.php
<?php
$ret = array('value' => mt_rand()+1000000000);
echo json_encode($ret);
?>
public class Uid {
private String value;
public String getValue() {
return value;
}
}
private RequestQueue mRequestQueue;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String url ="http://192.168.29.188/mt_rand.php";
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("MainActivity", response.toString());
Uid uid = new Gson().fromJson(response.toString(), Uid.class);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("MainActivity", error.toString());
}
}
);
mRequestQueue = Volley.newRequestQueue(this);
mRequestQueue.add(request);
}
No comments:
Post a Comment