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:
2011-01-31 05:08:08 +00:00
parent c52f835f7a
commit 1ad7485edb
3 changed files with 24 additions and 10 deletions

View File

@@ -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.

View File

@@ -27,7 +27,7 @@ public class LocationReceiver extends BroadcastReceiver{
private static final String TAG = "LocationReceiver";
private WakeLock mWakeLock;
private Context mContext;
/**
* acquires a wakelock to prevent the device's cpu from sleeping
* @param context

View File

@@ -6,6 +6,9 @@
*/
package com.TwentyCodes.android.TravelPost;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
@@ -34,8 +37,8 @@ public class LocationService extends Service implements LocationListener {
* Maximum running time in milliseconds
*/
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 WakeLock mWakeLock;
private Location mLocation;
@@ -51,6 +54,10 @@ public class LocationService extends Service implements LocationListener {
broadcastLocation();
}
};
private Notification mNotification;
private NotificationManager mNotificationManager;
/**
* a convince method for starting the service
@@ -83,7 +90,7 @@ public class LocationService extends Service implements LocationListener {
* @author ricky barrette
*/
private void broadcastLocation() {
Log.v(TAG, "broadcastLocation()");
Log.v(TravelPost.TAG, "broadcastLocation()");
if (mLocation != null) {
Intent locationUpdate = new Intent();
locationUpdate.setAction(LocationReceiver.ACTION_UPDATE);
@@ -114,12 +121,20 @@ public class LocationService extends Service implements LocationListener {
*/
@Override
public void onCreate(){
Log.v(TAG, "onCreate()");
Log.v(TravelPost.TAG, "onCreate()");
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_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();
//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
*/
@@ -136,6 +151,7 @@ public class LocationService extends Service implements LocationListener {
@Override
public void onDestroy(){
mLocationManager.removeUpdates(this);
mNotificationManager.cancel(SIMPLE_NOTFICATION_ID);
if(mWakeLock.isHeld())
mWakeLock.release();
}
@@ -183,7 +199,7 @@ public class LocationService extends Service implements LocationListener {
*/
@Override
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;
startLocationService();
}
@@ -194,7 +210,7 @@ public class LocationService extends Service implements LocationListener {
*/
@Override
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;
startLocationService();
return START_STICKY;