Fixed incorrect service intents, and made centralized static convice
methods for starting the location service closes #113 Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.TwentyCodes.android.LocationRinger"
|
||||
android:installLocation="internalOnly"
|
||||
android:versionCode="29"
|
||||
android:versionName="b71dc8a" >
|
||||
android:versionCode="35"
|
||||
android:versionName="73dbdc0" >
|
||||
|
||||
<uses-sdk android:minSdkVersion="7" />
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ import com.TwentyCodes.android.LocationRinger.R;
|
||||
import com.TwentyCodes.android.LocationRinger.debug.Debug;
|
||||
import com.TwentyCodes.android.LocationRinger.services.LocationService;
|
||||
import com.TwentyCodes.android.LocationRinger.ui.SettingsActivity;
|
||||
import com.TwentyCodes.android.debug.LocationLibraryConstants;
|
||||
|
||||
/**
|
||||
* This widget will be used to force a Location update from the users home screen
|
||||
@@ -50,9 +49,7 @@ public class GetLocationWidget extends AppWidgetProvider {
|
||||
for (int i=0; i<N; i++) {
|
||||
int appWidgetId = appWidgetIds[i];
|
||||
|
||||
Intent intent = new Intent(context, LocationService.class)
|
||||
.putExtra(LocationService.INTENT_EXTRA_REQUIRED_ACCURACY, Debug.ACCURACY)
|
||||
.setAction(LocationLibraryConstants.INTENT_ACTION_UPDATE);
|
||||
Intent intent = LocationService.getSingleShotServiceIntent(context);
|
||||
|
||||
//create a pending intent to start the post activity
|
||||
PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
||||
|
||||
@@ -16,7 +16,6 @@ import android.util.Log;
|
||||
import com.TwentyCodes.android.LocationRinger.debug.Debug;
|
||||
import com.TwentyCodes.android.LocationRinger.services.LocationService;
|
||||
import com.TwentyCodes.android.LocationRinger.ui.SettingsActivity;
|
||||
import com.TwentyCodes.android.debug.LocationLibraryConstants;
|
||||
import com.TwentyCodes.android.location.PassiveLocationListener;
|
||||
|
||||
/**
|
||||
@@ -43,17 +42,14 @@ public class SystemReceiver extends BroadcastReceiver {
|
||||
if(Debug.DEBUG)
|
||||
Log.d(TAG, "onReceive() ~"+intent.getAction());
|
||||
final SharedPreferences systemEventHistory = context.getSharedPreferences(TAG, Debug.SHARED_PREFS_MODE);
|
||||
Intent i = new Intent(context, LocationService.class)
|
||||
// .putExtra(LocationService.INTENT_EXTRA_PERIOD_BETWEEN_UPDATES, (long) (60000 * Integer.parseInt(context.getSharedPreferences(SettingsActivity.SETTINGS, 2).getString(SettingsActivity.UPDATE_INTVERVAL , "10"))))
|
||||
.putExtra(LocationService.INTENT_EXTRA_REQUIRED_ACCURACY, Debug.ACCURACY)
|
||||
.setAction(LocationLibraryConstants.INTENT_ACTION_UPDATE);
|
||||
|
||||
|
||||
/*
|
||||
* if the phone finishes booting, then start the service if the user enabled it
|
||||
*/
|
||||
if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
|
||||
if(context.getSharedPreferences(SettingsActivity.SETTINGS, Debug.SHARED_PREFS_MODE).getBoolean(SettingsActivity.START_ON_BOOT, false)){
|
||||
context.startService(i);
|
||||
LocationService.startMultiShotService(context);
|
||||
PassiveLocationListener.requestPassiveLocationUpdates(context, new Intent(context, PassiveLocationChangedReceiver.class));
|
||||
}
|
||||
}
|
||||
@@ -77,7 +73,7 @@ public class SystemReceiver extends BroadcastReceiver {
|
||||
if(intent.getAction().equals(Intent.ACTION_POWER_CONNECTED)){
|
||||
if (systemEventHistory.getBoolean(BATTERY_LOW, false)) {
|
||||
systemEventHistory.edit().remove(BATTERY_LOW).commit();
|
||||
context.startService(i);
|
||||
LocationService.startMultiShotService(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ package com.TwentyCodes.android.LocationRinger.services;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
@@ -18,6 +19,7 @@ import com.TwentyCodes.android.LocationRinger.debug.Debug;
|
||||
import com.TwentyCodes.android.LocationRinger.ui.ListActivity;
|
||||
import com.TwentyCodes.android.LocationRinger.ui.SettingsActivity;
|
||||
import com.TwentyCodes.android.SkyHook.SkyHookService;
|
||||
import com.TwentyCodes.android.debug.LocationLibraryConstants;
|
||||
import com.TwentyCodes.android.exception.ExceptionHandler;
|
||||
|
||||
/**
|
||||
@@ -30,25 +32,16 @@ public class LocationService extends SkyHookService {
|
||||
private SharedPreferences mSettings;
|
||||
private NotificationManager mNotificationManager;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.TwentyCodes.android.SkyHook.SkyHookService#onStartCommand(android.content.Intent, int, int)
|
||||
/**
|
||||
* convince method for getting the single shot service intent
|
||||
* @param context
|
||||
* @return service intent
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
this.mPeriod = Debug.UPDATE_INTERVAL;
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.TwentyCodes.android.SkyHook.SkyHookService#onDestroy()
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
this.mSettings.edit().remove(SettingsActivity.IS_SERVICE_STARTED).commit();
|
||||
this.mNotificationManager.cancel(this.GATHERING_LOCATION_ONGING_NOTIFICATION_ID);
|
||||
super.onDestroy();
|
||||
public static Intent getSingleShotServiceIntent(Context context) {
|
||||
return new Intent(context, LocationService.class)
|
||||
.putExtra(LocationLibraryConstants.INTENT_EXTRA_REQUIRED_ACCURACY, Debug.ACCURACY)
|
||||
.setAction(LocationLibraryConstants.INTENT_ACTION_UPDATE);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -64,6 +57,41 @@ public class LocationService extends SkyHookService {
|
||||
super.onCreate();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.TwentyCodes.android.SkyHook.SkyHookService#onDestroy()
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
this.mSettings.edit().remove(SettingsActivity.IS_SERVICE_STARTED).commit();
|
||||
this.mNotificationManager.cancel(this.GATHERING_LOCATION_ONGING_NOTIFICATION_ID);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.TwentyCodes.android.SkyHook.SkyHookService#onStartCommand(android.content.Intent, int, int)
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
this.mPeriod = Debug.UPDATE_INTERVAL;
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the location service in multi shot mode
|
||||
* @param context
|
||||
* @return
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public static ComponentName startMultiShotService(final Context context){
|
||||
Intent i = new Intent(context, LocationService.class)
|
||||
.putExtra(LocationLibraryConstants.INTENT_EXTRA_PERIOD_BETWEEN_UPDATES, Debug.UPDATE_INTERVAL)
|
||||
.putExtra(LocationLibraryConstants.INTENT_EXTRA_REQUIRED_ACCURACY, Debug.ACCURACY)
|
||||
.setAction(LocationLibraryConstants.INTENT_ACTION_UPDATE);
|
||||
return context.startService(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* starts a simple ongoing notification to inform the user that we are gathering location
|
||||
* @author ricky barrette
|
||||
@@ -76,4 +104,14 @@ public class LocationService extends SkyHookService {
|
||||
notifyDetails.flags |= Notification.FLAG_ONGOING_EVENT;
|
||||
this.mNotificationManager.notify(this.GATHERING_LOCATION_ONGING_NOTIFICATION_ID, notifyDetails);
|
||||
}
|
||||
|
||||
/**
|
||||
* starts the service in single shot mode
|
||||
* @param context
|
||||
* @return
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public static ComponentName startSingleShotService(final Context context){
|
||||
return context.startService(getSingleShotServiceIntent(context));
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,8 @@
|
||||
*/
|
||||
package com.TwentyCodes.android.LocationRinger.services;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.ContentValues;
|
||||
@@ -119,29 +116,6 @@ public class RingerProcessingService extends Service {
|
||||
mBluetoothAdapter.enable();
|
||||
else
|
||||
mBluetoothAdapter.disable();
|
||||
|
||||
/*
|
||||
* update interval
|
||||
*/
|
||||
if(values.containsKey(RingerDatabase.KEY_UPDATE_INTERVAL))
|
||||
if (values.get(RingerDatabase.KEY_UPDATE_INTERVAL) != null){
|
||||
Intent i = new Intent(this, LocationService.class)
|
||||
.putExtra(LocationService.INTENT_EXTRA_REQUIRED_ACCURACY, Debug.ACCURACY)
|
||||
.setAction(LocationLibraryConstants.INTENT_ACTION_UPDATE);
|
||||
PendingIntent pi = PendingIntent.getService(this, LocationService.REQUEST_CODE, i, 0);
|
||||
|
||||
final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
||||
|
||||
/*
|
||||
* cancel the existing schedule
|
||||
*/
|
||||
am.cancel(pi);
|
||||
|
||||
/*
|
||||
* reschedule the location service
|
||||
*/
|
||||
am.set(AlarmManager.RTC_WAKEUP, Calendar.getInstance().getTimeInMillis() + (long) (60000 * Integer.parseInt(values.getAsString(RingerDatabase.KEY_UPDATE_INTERVAL))), pi);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -77,10 +77,7 @@ public class CheckLocationShortcut extends Activity {
|
||||
/*
|
||||
* start the location service in single shot mode
|
||||
*/
|
||||
Intent service = new Intent(this, LocationService.class)
|
||||
.putExtra(LocationService.INTENT_EXTRA_REQUIRED_ACCURACY, Debug.ACCURACY)
|
||||
.setAction(LocationLibraryConstants.INTENT_ACTION_UPDATE);
|
||||
this.startService(service);
|
||||
LocationService.startSingleShotService(this);
|
||||
|
||||
this.finish();
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ import com.TwentyCodes.android.LocationRinger.debug.Debug;
|
||||
import com.TwentyCodes.android.LocationRinger.receivers.PassiveLocationChangedReceiver;
|
||||
import com.TwentyCodes.android.LocationRinger.services.LocationService;
|
||||
import com.TwentyCodes.android.SkyHook.SkyHookRegistration;
|
||||
import com.TwentyCodes.android.debug.LocationLibraryConstants;
|
||||
import com.TwentyCodes.android.location.PassiveLocationListener;
|
||||
import com.skyhookwireless.wps.RegistrationCallback;
|
||||
import com.skyhookwireless.wps.WPSContinuation;
|
||||
@@ -389,10 +388,7 @@ public class ListActivity extends Activity implements OnItemClickListener, OnCli
|
||||
// cancel the previous service
|
||||
LocationService.stopService(this).run();
|
||||
//start the new service
|
||||
Intent i = new Intent(this, LocationService.class)
|
||||
.putExtra(LocationService.INTENT_EXTRA_REQUIRED_ACCURACY, Debug.ACCURACY)
|
||||
.setAction(LocationLibraryConstants.INTENT_ACTION_UPDATE);
|
||||
this.startService(i);
|
||||
LocationService.startMultiShotService(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user