android - What should be used to substitute BasicNameValuePair in building URL? -


i using below code build url networking. have been using basicnamevaluepair , urlencodedutils build url since android 5.0 both have been deprecated. shall use create url?

list<namevaluepair> pairs = new arraylist<namevaluepair>();  pairs.add(new basicnamevaluepair("appid", "0000000000000000"));                 pairs.add(new basicnamevaluepair("lat", string.valueof(latitude)));                 pairs.add(new basicnamevaluepair("lon", string.valueof(longitude)));                 pairs.add(new basicnamevaluepair("type", "accurate"));                 pairs.add(new basicnamevaluepair("units", "metric"));                  // create new url                 url url = new url("http://api.openweathermap.org/data/2.5/weather" + "?" + urlencodedutils.format(pairs, "utf-8")); 

@samvid ...use volley library

public static void postnewcomment(context context,final useraccount useraccount,final string comment,final int blogid,final int postid){ mpostcommentresponse.requeststarted(); requestqueue queue = volley.newrequestqueue(context); stringrequest sr = new stringrequest(request.method.post,"http://api.someservice.com/post/comment", new response.listener<string>() {     @override     public void onresponse(string response) {         mpostcommentresponse.requestcompleted();     } }, new response.errorlistener() {     @override     public void onerrorresponse(volleyerror error) {         mpostcommentresponse.requestendedwitherror(error);     } }){     @override     protected map<string,string> getparams(){         map<string,string> params = new hashmap<string, string>();         params.put("user",useraccount.getusername());         params.put("pass",useraccount.getpassword());         params.put("comment", uri.encode(comment));         params.put("comment_post_id",string.valueof(postid));         params.put("blogid",string.valueof(blogid));          return params;     }      @override     public map<string, string> getheaders() throws authfailureerror {         map<string,string> params = new hashmap<string, string>();         params.put("content-type","application/x-www-form-urlencoded");         return params;     } }; queue.add(sr); }  public interface postcommentresponselistener { public void requeststarted(); public void requestcompleted(); public void requestendedwitherror(volleyerror error); } 

this basic example ... can use acc. need


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -