java - NameValuePair and httpParams is deprecated, how to solve it? -


i tried search answer there not complete answer. code going select image gallery , upload server database.

now code has 2 error. 1. namevaluepair 2. httpparams

this code

 @override         protected void doinbackground(void...params){             bytearrayoutputstream bytearrayoutputstream=new bytearrayoutputstream();             image.compress(bitmap.compressformat.jpeg,100,bytearrayoutputstream);             string encodedimage= base64.encodetostring(bytearrayoutputstream.tobytearray(),base64.default);              arraylist <namevaluepair> datatosend=new arraylist<>();             datatosend.add(new basicnamevaluepair("image",encodedimage));             datatosend.add(new basicnamevaluepair("name",name));              httpparams httprequestparams=gethttprequestparams() ;              httpclient client=new defaulthttpclient(httprequestparams);             httppost post=new httppost();             return null;         }          @override         protected void onpostexecute(void avoid){             super.onpostexecute(avoid);         }     }      private httpparams gethttprequestparams(){         httpparams httprequestparams=new basichttpparams();         httpconnectionparams.setconnectiontimeout(httprequestparams,100*30);         httpconnectionparams.setsotimeout(httprequestparams,1000*30);         return httprequestparams;      } 

i suggest try android's volley. i'm gonna show sample code. can search on internet other samples too. play it.

 requestqueue queue = volley.newrequestqueue(activity.this);     stringrequest sr = new stringrequest(request.method.post, url,             new response.listener<string>() {                 @override                 public void onresponse(string s) {                     int success;                     try {                         jsonobject object = new jsonobject(s.tostring());                         success = object.getint("success");                         log.wtf("success", string.valueof(success));                         log.wtf("message", object.getstring("message"));                         if(success==1){                             //do here                         }else{                            //do here                         }                     }catch (exception e){                         e.printstacktrace();                     }                  }             }, new response.errorlistener(){         @override         public void onerrorresponse(volleyerror volleyerror) {             volleyerror.printstacktrace();         }     }){         @override         protected map<string, string> getparams() throws authfailureerror {             map<string,string> params = new hashmap<string, string>();             params.put("id", id);             return params;         }     };queue.add(sr); 

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -