added an ongoing notification to the location service, that is started with the service, and removed when the service finished
This commit is contained in:
@@ -1,2 +0,0 @@
|
|||||||
I created TwitterServices.java to handle the twitter services.
|
|
||||||
the reason why it was failing before is that i created a request token to get an auth url, and then i would create a new one when i get the auth code.
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class LocationReceiver extends BroadcastReceiver{
|
|||||||
private static final String TAG = "LocationReceiver";
|
private static final String TAG = "LocationReceiver";
|
||||||
private WakeLock mWakeLock;
|
private WakeLock mWakeLock;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* acquires a wakelock to prevent the device's cpu from sleeping
|
* acquires a wakelock to prevent the device's cpu from sleeping
|
||||||
* @param context
|
* @param context
|
||||||
|
|||||||
@@ -6,6 +6,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.TwentyCodes.android.TravelPost;
|
package com.TwentyCodes.android.TravelPost;
|
||||||
|
|
||||||
|
import android.app.Notification;
|
||||||
|
import android.app.NotificationManager;
|
||||||
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -34,8 +37,8 @@ public class LocationService extends Service implements LocationListener {
|
|||||||
* Maximum running time in milliseconds
|
* Maximum running time in milliseconds
|
||||||
*/
|
*/
|
||||||
private final long MAX_RUN_TIME = 180000L;
|
private final long MAX_RUN_TIME = 180000L;
|
||||||
|
|
||||||
public static final String TAG = "LocationService";
|
private static final int SIMPLE_NOTFICATION_ID = 234098752;
|
||||||
private LocationManager mLocationManager;
|
private LocationManager mLocationManager;
|
||||||
private WakeLock mWakeLock;
|
private WakeLock mWakeLock;
|
||||||
private Location mLocation;
|
private Location mLocation;
|
||||||
@@ -51,6 +54,10 @@ public class LocationService extends Service implements LocationListener {
|
|||||||
broadcastLocation();
|
broadcastLocation();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private Notification mNotification;
|
||||||
|
|
||||||
|
private NotificationManager mNotificationManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a convince method for starting the service
|
* a convince method for starting the service
|
||||||
@@ -83,7 +90,7 @@ public class LocationService extends Service implements LocationListener {
|
|||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
private void broadcastLocation() {
|
private void broadcastLocation() {
|
||||||
Log.v(TAG, "broadcastLocation()");
|
Log.v(TravelPost.TAG, "broadcastLocation()");
|
||||||
if (mLocation != null) {
|
if (mLocation != null) {
|
||||||
Intent locationUpdate = new Intent();
|
Intent locationUpdate = new Intent();
|
||||||
locationUpdate.setAction(LocationReceiver.ACTION_UPDATE);
|
locationUpdate.setAction(LocationReceiver.ACTION_UPDATE);
|
||||||
@@ -114,12 +121,20 @@ public class LocationService extends Service implements LocationListener {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(){
|
public void onCreate(){
|
||||||
Log.v(TAG, "onCreate()");
|
Log.v(TravelPost.TAG, "onCreate()");
|
||||||
|
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
||||||
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||||
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
|
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TravelPost.TAG);
|
||||||
mWakeLock.acquire();
|
mWakeLock.acquire();
|
||||||
|
|
||||||
|
//display notification
|
||||||
|
PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(this, TravelPost.class), android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
mNotification = new Notification(R.drawable.icon, "Getting Location", System.currentTimeMillis());
|
||||||
|
mNotification.flags |= Notification.FLAG_ONGOING_EVENT;
|
||||||
|
mNotification.setLatestEventInfo(this, "Travel Post", "Gathering location...", intent);
|
||||||
|
mNotificationManager.notify(SIMPLE_NOTFICATION_ID, mNotification);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* que the fail safe runnable to kill the report location and kill it self after the MAX_RUN_TIME has been meet
|
* que the fail safe runnable to kill the report location and kill it self after the MAX_RUN_TIME has been meet
|
||||||
*/
|
*/
|
||||||
@@ -136,6 +151,7 @@ public class LocationService extends Service implements LocationListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onDestroy(){
|
public void onDestroy(){
|
||||||
mLocationManager.removeUpdates(this);
|
mLocationManager.removeUpdates(this);
|
||||||
|
mNotificationManager.cancel(SIMPLE_NOTFICATION_ID);
|
||||||
if(mWakeLock.isHeld())
|
if(mWakeLock.isHeld())
|
||||||
mWakeLock.release();
|
mWakeLock.release();
|
||||||
}
|
}
|
||||||
@@ -183,7 +199,7 @@ public class LocationService extends Service implements LocationListener {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onStart(Intent intent, int startId) {
|
public void onStart(Intent intent, int startId) {
|
||||||
Log.i(TAG, "onStart.Service started with start id of: " + startId);
|
Log.i(TravelPost.TAG, "onStart.Service started with start id of: " + startId);
|
||||||
mStartId = startId;
|
mStartId = startId;
|
||||||
startLocationService();
|
startLocationService();
|
||||||
}
|
}
|
||||||
@@ -194,7 +210,7 @@ public class LocationService extends Service implements LocationListener {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
Log.i(TAG , "onStartCommand.Service started with start id of: " + startId);
|
Log.i(TravelPost.TAG , "onStartCommand.Service started with start id of: " + startId);
|
||||||
mStartId = startId;
|
mStartId = startId;
|
||||||
startLocationService();
|
startLocationService();
|
||||||
return START_STICKY;
|
return START_STICKY;
|
||||||
|
|||||||
Reference in New Issue
Block a user