java - Send data to the server in service class -


i trying send data server when user mobile internet become active, in application whenever internet connection active broadcast receiver call service method. below method. trying both post , method not request site. not able print "i in service5"(below have printed).it not update database.

public class localservice extends service { .... .... public void sendfeedback(){            system.out.println("i in service4");         string filename =mainscreenactivity.username;           httpurlconnection urlconnection = null;         final string target_uri =                 "http://readoline.com/feedback.php";               try {             bufferedreader mreader = new bufferedreader(new inputstreamreader(getapplicationcontext().openfileinput(filename)));             string line;             stringbuffer buffer = new stringbuffer();               while ((line = mreader.readline()) != null) {                 buffer.append(line + "\n");             }             system.out.println(buffer.tostring());               try {                 system.out.println("i in service41"+buffer.tostring());                 uri builduri = uri.parse("http://readoline.com/feedback.php" + "?").buildupon()                         .appendqueryparameter("user_id", filename)                         .appendqueryparameter("feedback", buffer.tostring())                         .build();                  url url = new url(builduri.tostring());                    urlconnection = (httpurlconnection) url.openconnection();                 urlconnection.setrequestmethod("get");                 urlconnection.connect();                  system.out.println("i in service44");             /*  printwriter out=new printwriter(urlconnection.getoutputstream());                 out.write("user_id="+filename);                 out.write("&");                 out.write("feedback="+buffer.tostring());             */                     system.out.println("i in service5");                   //  log.e(log_tag,datatosend.tostring());                   //out.close();                 // read input stream string               }catch (ioexception e){                 system.out.println("i in service6");                 e.printstacktrace();             }finally {                 if (urlconnection!=null){                     urlconnection.disconnect();                 }             }            }catch(exception e){          }     } } 


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -