Android - 如何从网址获取价值

I want to get a value from url in android.

For example:

In android i can write app id like this:

<string name="app_id">123456789012</string>

But i want to get app_id from url like this:

<string name="app_id">http://www.domain.com/index.php</string>

In the http://www.domain.com/index.php the only app_id is written 123456789012 and i want to retrieve this id in the string.

I search a lot on google and i found "android volley" but i'm understand how to use this.

String url = "http://httpbin.org/get?site=code&network=tutsplus";

JsonObjectRequest jsonRequest = new JsonObjectRequest
    (Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            // the response is already constructed as a JSONObject!
            try {
                response = response.getJSONObject("args");
                String site = response.getString("site"),
                        network = response.getString("network");
                System.out.println("Site: "+site+"
Network: "+network);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            error.printStackTrace();
        }
    });

Volley.newRequestQueue(this).add(jsonRequest);
查看全部
duandanxiu6965
duandanxiu6965
2016/01/27 14:24
  • android
  • php
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复