Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. public class SendServer extends AsyncTask<String, Void, Void> {
  2.  
  3. @TargetApi(Build.VERSION_CODES.CUPCAKE)
  4. protected void onPreExecute() {
  5. super.onPreExecute();
  6. //GPSTracker gps = new GPSTracker();
  7. //if(gps.canGetLocation()){}
  8. //tvInfo.setText("Полез на крышу");
  9. }
  10.  
  11. protected Void doInBackground(String... params) {
  12. try {
  13.  
  14.  
  15. //System.out.println("params 0 : "+params[0]);
  16. HttpPost httpost = new HttpPost("http://i.enot-pomi4nuk.com.ua/appgps/send.php?text="+params[0]);
  17. DefaultHttpClient httpclient = new DefaultHttpClient();
  18.  
  19. List <NameValuePair> nvps = new ArrayList <NameValuePair>();
  20.  
  21. httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
  22. ResponseHandler<String> responseHandler = new BasicResponseHandler();
  23. httpclient.execute(httpost, responseHandler);
  24. TimeUnit.SECONDS.sleep(15);
  25.  
  26. } catch (UnsupportedEncodingException e) {
  27. // TODO Auto-generated catch block
  28. System.out.println("UnsupportedEncodingException");
  29. e.printStackTrace();
  30. } catch (ClientProtocolException e) {
  31. // TODO Auto-generated catch block
  32. System.out.println("ClientProtocolException");
  33. e.printStackTrace();
  34. } catch (IOException e) {
  35. System.out.println("IOException");
  36. // TODO Auto-generated catch block
  37. e.printStackTrace();
  38. } catch (InterruptedException e) {
  39. // TODO Auto-generated catch block
  40. e.printStackTrace();
  41. }
  42. return null;
  43. }
  44.  
  45. }
  46.  
  47. SendServer cattask = new SendServer();
  48. cattask.execute("test");
  49.  
  50. static String test="ok";
  51. SendServer cattask = new SendServer();
  52. cattask.execute(test);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement