public class LocationServiceLauncherReciever extends BroadcastReceiver {
- private final String TAG = getClass().getSimpleName();
-
- @Override
- public void onReceive(Context context, Intent intent) {
- Intent deviceTrackingIntent = new Intent();
- deviceTrackingIntent.setAction("eu.alefzero.owncloud.location.LocationUpdateService");
- SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
- boolean trackDevice = preferences.getBoolean("enable_devicetracking", true);
-
- // Used in Preferences activity so that tracking is disabled or reenabled
- if(intent.hasExtra("TRACKING_SETTING")){
- trackDevice = intent.getBooleanExtra("TRACKING_SETTING", true);
- }
-
- startOrStopDeviceTracking(context, trackDevice);
- }
-
- /**
- * Used internally. Starts or stops the device tracking service
- *
- * @param trackDevice
- * true to start the service, false to stop it
- */
- private void startOrStopDeviceTracking(Context context, boolean trackDevice) {
- Intent deviceTrackingIntent = new Intent();
- deviceTrackingIntent
- .setAction("eu.alefzero.owncloud.location.LocationUpdateService");
- if (!isDeviceTrackingServiceRunning(context) && trackDevice) {
- Log.d(TAG, "Starting device tracker service");
- context.startService(deviceTrackingIntent);
- } else if (isDeviceTrackingServiceRunning(context) && !trackDevice) {
- Log.d(TAG, "Stopping device tracker service");
- context.stopService(deviceTrackingIntent);
- }
- }
-
- /**
- * Checks to see whether or not the LocationUpdateService is running
- *
- * @return true, if it is. Otherwise false
- */
- private boolean isDeviceTrackingServiceRunning(Context context) {
- ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
- for (RunningServiceInfo service : manager
- .getRunningServices(Integer.MAX_VALUE)) {
- if (getClass().getName().equals(service.service.getClassName())) {
- return true;
- }
- }
- return false;
- }
+ private final String TAG = getClass().getSimpleName();
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Intent deviceTrackingIntent = new Intent();
+ deviceTrackingIntent
+ .setAction("eu.alefzero.owncloud.location.LocationUpdateService");
+ SharedPreferences preferences = PreferenceManager
+ .getDefaultSharedPreferences(context);
+ boolean trackDevice = preferences.getBoolean("enable_devicetracking",
+ true);
+
+ // Used in Preferences activity so that tracking is disabled or
+ // reenabled
+ if (intent.hasExtra("TRACKING_SETTING")) {
+ trackDevice = intent.getBooleanExtra("TRACKING_SETTING", true);
+ }
+
+ startOrStopDeviceTracking(context, trackDevice);
+ }
+
+ /**
+ * Used internally. Starts or stops the device tracking service
+ *
+ * @param trackDevice true to start the service, false to stop it
+ */
+ private void startOrStopDeviceTracking(Context context, boolean trackDevice) {
+ Intent deviceTrackingIntent = new Intent();
+ deviceTrackingIntent
+ .setAction("eu.alefzero.owncloud.location.LocationUpdateService");
+ if (!isDeviceTrackingServiceRunning(context) && trackDevice) {
+ Log.d(TAG, "Starting device tracker service");
+ context.startService(deviceTrackingIntent);
+ } else if (isDeviceTrackingServiceRunning(context) && !trackDevice) {
+ Log.d(TAG, "Stopping device tracker service");
+ context.stopService(deviceTrackingIntent);
+ }
+ }
+
+ /**
+ * Checks to see whether or not the LocationUpdateService is running
+ *
+ * @return true, if it is. Otherwise false
+ */
+ private boolean isDeviceTrackingServiceRunning(Context context) {
+ ActivityManager manager = (ActivityManager) context
+ .getSystemService(Context.ACTIVITY_SERVICE);
+ for (RunningServiceInfo service : manager
+ .getRunningServices(Integer.MAX_VALUE)) {
+ if (getClass().getName().equals(service.service.getClassName())) {
+ return true;
+ }
+ }
+ return false;
+ }
}