Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends AppCompatActivity {
- String strJson = "https://plaza.one/api/status/";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- artist = findViewById(R.id.artist);
- title = findViewById(R.id.title);
- album = findViewById(R.id.album);
- /************ JSON data ***********/
- RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
- JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
- Request.Method.GET, strJson,
- null,
- new Response.Listener<JSONObject>() {
- @Override
- public void onResponse(JSONObject response) {
- try{
- JSONArray array = response.getJSONArray("playback");
- for(int i=0;i<array.length();i++){
- JSONObject student = array.getJSONObject(i);
- String artisti = student.getString("artist");
- String titlei = student.getString("title");
- String albumi = student.getString("album");
- artist.setText("Artist : "+artisti);
- title.setText("title : "+titlei);
- album.setText("album : "+albumi);
- }
- }catch (JSONException e){
- e.printStackTrace();
- }
- }
- },
- new Response.ErrorListener(){
- @Override
- public void onErrorResponse(VolleyError error){
- //Toast error
- }
- }
- );
- requestQueue.add(jsonObjectRequest);
- }
- }
Add Comment
Please, Sign In to add comment