Advertisement
ScottHelme

GPS Tracker - MainActivity

Jul 18th, 2013
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.27 KB | None | 0 0
  1. package com.prodev.litetrack;
  2.  
  3. import java.io.IOException;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6.  
  7. import org.apache.http.HttpResponse;
  8. import org.apache.http.NameValuePair;
  9. import org.apache.http.client.ClientProtocolException;
  10. import org.apache.http.client.HttpClient;
  11. import org.apache.http.client.entity.UrlEncodedFormEntity;
  12. import org.apache.http.client.methods.HttpPost;
  13. import org.apache.http.impl.client.DefaultHttpClient;
  14. import org.apache.http.message.BasicNameValuePair;
  15.  
  16. import android.app.Service;
  17. import android.content.Context;
  18. import android.content.Intent;
  19. import android.os.AsyncTask;
  20. import android.os.IBinder;
  21. import android.os.NetworkOnMainThreadException;
  22. import android.util.Log;
  23.  
  24. public class MainActivity extends Service {
  25.     private LocationServices locationServices;
  26.     private Context context;
  27.    
  28.     @Override
  29.     public void onCreate() {
  30.         super.onCreate();
  31.         context = this;
  32.         locationServices = new LocationServices(context);
  33.         new LocationWorker().execute(new Boolean[] {true});
  34.     }
  35.  
  36.     class LocationWorker extends AsyncTask<Boolean, Integer, Boolean> {
  37.            
  38.         @Override
  39.         protected void onPreExecute() {}
  40.         @Override
  41.         protected void onPostExecute(Boolean result) {
  42.             new InternetWorker().execute(new Boolean[] {true});
  43.         }
  44.         @Override
  45.         protected Boolean doInBackground(Boolean... params) {
  46.             while(locationServices.gotLocation() == false){/*do nothing*/}
  47.             return true;
  48.         }
  49.     }
  50.    
  51.     class InternetWorker extends AsyncTask<Boolean, Integer, Boolean> {
  52.         @Override
  53.         protected void onPreExecute() {}      
  54.         @Override
  55.         protected void onPostExecute(Boolean result) {
  56.             try {
  57.                 Thread.sleep(60000);
  58.             } catch (InterruptedException e) {
  59.                 e.printStackTrace();
  60.             }
  61.             new LocationWorker().execute(new Boolean[] {true});
  62.         }
  63.        
  64.         @Override
  65.         protected Boolean doInBackground(Boolean... params) {
  66.             Log.i("GPS", "Got location.");
  67.            
  68.             /* write to file here */
  69.            
  70.             return true;
  71.         }
  72.     }
  73.  
  74.     @Override
  75.     public IBinder onBind(Intent intent) {
  76.         // TODO Auto-generated method stub
  77.         return null;
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement