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.
|
||||
|
||||
@@ -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;
|
||||
@@ -35,7 +38,7 @@ public class LocationService extends Service implements LocationListener {
|
||||
*/
|
||||
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;
|
||||
@@ -52,6 +55,10 @@ public class LocationService extends Service implements LocationListener {
|
||||
}
|
||||
};
|
||||
|
||||
private Notification mNotification;
|
||||
|
||||
private NotificationManager mNotificationManager;
|
||||
|
||||
/**
|
||||
* a convince method for starting the service
|
||||
* @param context
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user