Linking PHP with Android Studio to get Firebase Tokens -


can me understand piece of code. in advance.what purpose of okhttpclient? there alternative block of code?

private void registertoken(string token) {      okhttpclient client = new okhttpclient();     requestbody body = new formbody.builder()             .add("token",token)             .build();      request request = new request.builder()             .url("notify.php")             .post(body)             .build();      try {         client.newcall(request).execute();     } catch (ioexception e) {         e.printstacktrace();     } } 

you can use loopj library api call. simple .follow steps android. add dependency in gradle

 compile 'com.loopj.android:android-async-http:1.4.9' 

request web api

 string url="your url here";   requestparams requestparams = new requestparams();          requestparams.put("token", usertoken);     new asynchttpclient().post(url,requestparams, new asynchttpresponsehandler() {         @override         public void onsuccess(int statuscode, header[] headers, byte[] responsebody) {           string rs = new string(responsebody);            @override         public void onfailure(int statuscode, header[] headers, byte[] responsebody, throwable error) {          }     }); 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -