android get url from edit text and use it in rest api to upload data -


here android rest request code url edit text using id "getstring" gets flagged(can't resolved). please

class restrequest {     //final string add_stroke_url = "";      final string add_stroke_url = new string[]{ getstring(r.id.buttonuploadurl)};      public boolean success = null;     private jsonobject params;     private string strokeid;     private hashset<point> localpoints;     private strokemanagercallback callback;       public static string encode(object x) {         try {             return urlencoder.encode(string.valueof(x),"utf-8");         } catch (unsupportedencodingexception e) {             return(string.valueof(x));         }     }       public restrequest(jsonobject params,string strokeid,set<point> points,strokemanagercallback callback)     {         this.params = params;          this.strokeid = strokeid;          this.localpoints = new hashset<point>();         this.localpoints.addall(points);          this.callback = callback;          new executerest().execute();      }      private class executerest extends asynctask<void, void, string>     {          protected string doinbackground(void ...arg0)         {              /* build url query */             stringbuffer local = new stringbuffer(add_stroke_url);             if(params != null)             {                 local.append("?");                 iterator<?> k = params.keys();                 while(k.hasnext()){                     try {                         string key = (string) k.next();                         object value = params.get(key);                          local.append(encode(key));                         local.append("=");                         local.append(encode(value));                         if(k.hasnext()){                             local.append("&");                         }                     }                     catch (jsonexception e) {e.printstacktrace();}                 }             }              httpurlconnection urlconn = null;             stringbuffer response = new stringbuffer("error");             try             {                 url url = new url(local.tostring());                 urlconn = (httpurlconnection) url.openconnection();                 urlconn.setrequestmethod("get");                 urlconn.setdoinput(true);                 urlconn.setusecaches(false);                 urlconn.setrequestproperty("content-type", "application/json");                 urlconn.connect();                  //get response                 inputstream = urlconn.getinputstream();                 bufferedreader rd = new bufferedreader(newinputstreamreader(is));                 string line;                 response = new stringbuffer();                 try{                     while((line = rd.readline()) != null) {                         response.append(line);                     }                 }                 finally{                     if(urlconn != null){                         urlconn.disconnect();                         urlconn = null;                     }                     if(rd != null){                         rd.close();                         rd = null;                     }                 }                  if(callback != null){                     callback.onsuccess(strokeid, localpoints);                 }             } catch (connectexception e) {                 callback.onfailure(strokeid, localpoints);             } catch (unknownhostexception e) {                 callback.onfailure(strokeid, localpoints);             } catch (malformedurlexception e) {                 e.printstacktrace();             } catch (eofexception e) {                 response = new stringbuffer("no response server");             } catch (ioexception e) {                 e.printstacktrace();             } catch (runtimeexception e) {                 e.printstacktrace();             }             finally{                 if(urlconn != null){                     urlconn.disconnect();                 }             }             return response.tostring();         }     } 

you can string resources

resources res = context.getresources(); final string add_stroke_url = new string[]{ res.getstring(r.id.buttonuploadurl)}; 

and can pass url in acycnctask class

public restrequest(jsonobject params,string                     strokeid,set<point>points,strokemanagercallback callback){     this.params = params;    this.strokeid = strokeid;    this.localpoints = new hashset<point>();    this.localpoints.addall(points);    this.callback = callback;     new executerest(/*pass url here in doinbackground method */) .execute();   }  private class executerest extends asynctask<string, void, string>{     protected string doinbackground(string ...arg0){       //get url in arg0 variable       stringbuffer local = new stringbuffer(arg0[0]);             .            .            .       //rest of yours ... 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -