php - Android - how to get value from url -


i want value url in android.

for example:

in android can write app id this:

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

but want app_id url this:

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

in http://www.domain.com/index.php app_id written 123456789012 , want retrieve id in string.

i search lot on google , found "android volley" i'm understand how 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) {             // response constructed jsonobject!             try {                 response = response.getjsonobject("args");                 string site = response.getstring("site"),                         network = response.getstring("network");                 system.out.println("site: "+site+"\nnetwork: "+network);             } catch (jsonexception e) {                 e.printstacktrace();             }         }     }, new response.errorlistener() {          @override         public void onerrorresponse(volleyerror error) {             error.printstacktrace();         }     });  volley.newrequestqueue(this).add(jsonrequest); 

android volley framework allows make http request quite easy.

when trying open page in browser, making http request url. see on page - returned in response request html code or else. so, if want retrive data url need make http request url , parse response.

how request volley: need extend own class 1 of request classes of volley, , add request query (which means execution of request)

public class getrequest extends request<string> {  private response.listener<string> responselistener;  public getrequest (string login, string password) {     super(method.get, http://www.domain.com/index.php,     new response.errorlistener() {                 @override                 public void onerrorresponse(volleyerror error) {                  }             });      responselistener = new response.listener<string>() {         @override         public void onresponse(string response) {             //parse response here         }     }; }  @override protected response<string> parsenetworkresponse(networkresponse response) {     string parsed;     try {         parsed = string.valueof(new string(response.data, httpheaderparser.parsecharset(response.headers)));     } catch (unsupportedencodingexception e) {         parsed = string.valueof(new string(response.data));     }     return response.success(parsed, httpheaderparser.parsecacheheaders(response)); }  @override protected void deliverresponse(string response) {     responselistener.onresponse(response); } } 

you should although notice, when extending request class, specifying type of expeted response. in current example string.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -