Code example for Location

Methods: setProvidertoString

0
			Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
			if (location == null) { 
				location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
				if (location == null) { 
					// We'll just write an empty location 
					location = new Location("prx"); 
				} 
			} 
			 
			if (intent.hasExtra(LocationManager.KEY_PROXIMITY_ENTERING)){ 
				if (intent.getBooleanExtra(LocationManager.KEY_PROXIMITY_ENTERING, true)==true) { 
					location.setProvider("prx_enter"); 
				} else { 
					location.setProvider("prx_exit"); 
				} 
			} 
			addLocationToDB(location); 
		} 
	}; 
 
	@Override 
	public int onStartCommand(Intent intent, int flags, int startId) {
		Log.i(TAG, "onStartCommand()");
		super.onStartCommand(intent, flags, startId);
		// We want this service to continue running until it is explicitly 
		// stopped, so return sticky. 
		return START_STICKY;
	} 
 
	@Override 
	public void onCreate() { 
		Log.i(TAG, "onCreate()");
		dbAdapter = new LocationDbAdapter(this);
		dbAdapter.open();
 
		requestLocationUpdates(); 
		addProximityAlert(); 
 
		// TODO Normally this is declared in the Manifest 
		IntentFilter intentFilter = new IntentFilter();
		intentFilter.addAction("com.shinetech.android.PREFERENCES_CHANGED");
		this.registerReceiver(this.broadcastReceiver, intentFilter);
 
	} 
 
	@Override 
	public void onDestroy() { 
		Log.i(TAG, "onDestroy()");
		super.onDestroy(); 
		dbAdapter.close();
		locationManager.removeUpdates(this);
	} 
 
	@Override 
	public IBinder onBind(Intent intent) {
		return null; 
	} 
 
	public void onLocationChanged(Location location) {
		addLocationToDB(location);
	} 
 
	private void addLocationToDB(Location location) {
		Log.i(TAG, "Location changed: " + location.toString());
		dbAdapter.addLocation(location);
		Intent intent = new Intent("com.shinetech.android.UPDATE_UI");
		sendBroadcast(intent);
		Log.i(TAG, "UPDATE_UI intent broadcasted");
	}