[android-developers] Re: Always-on GPS: widget or app?

2011-10-01 Thread lbendlin
I haven't seen the issues with concurrent GPS access that you describe.  
nevertheless you may want to anticipate a situation when another program is 
currently actively using the GPS. In such a case you could ask the passive 
provider first, and only if that location is too old or to imprecise then 
you would fire up your own locationlistener.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Always-on GPS: widget or app?

2011-10-01 Thread Studio LFP
I hoping this was fixed along the way and the issue not updated.  I had to 
drop a part of an internal application for a company because of this bug.

And like lbendlin said, you could just check the last known and see if it 
was recent enough to use.

private static final int TIME_WINDOW = 1; // 10 Second window

LocationManager lmMgr = (LocationManager)getSystemService( 
Context.LOCATION_SERVICE );
Location lLast = lmMgr.getLastKnownLocation( LocationManager.GPS_PROVIDER );

if( System.currentTimeMillis() - lLast.getTime()  TIME_WINDOW )
{
// Use last known. 
}

You can always do this first and if something else is using the GPS you 
could get a good fix fairly quickly.  Just know that this can be VERY old 
and you would want to do proper checking on it.

Steven
Studio LFP
http://www.studio-lfp.com

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Always-on GPS: widget or app?

2011-09-30 Thread emeve
Many thanks for the helpful info, Steven .
I'm sure that will save me a lot of time.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Always-on GPS: widget or app?

2011-09-30 Thread Pinheiro
Just to clarify one thing:
 you don't want to use the requestLocationUpdates().
I suppose you meant: you don't want to call requestLocationUpdates()
for continuous updates, right?In the BroadcastReceiver activity, I'll
call the requestLocationUpdates() and then removeUpdate() as soon as
there is a fix. Also, the new alarm will be created only after a fix
so that there isn't a possibility of alarm conflict (one alarm is not
done with the GPS and then there's a new one).

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Always-on GPS: widget or app?

2011-09-30 Thread Studio LFP
Correct.

Note that this may have been fixed somewhere along the way and they haven't 
taken time to mark that issue resolved. As you can see, the Droid and others 
I confirmed that on were Android 2.0.1, which is hardly in use today.

At the time of posting that issue, I spent a ton of time trying to figure 
out why I couldn't get a lock in another application at any speed while I 
had a background location request set at 15 minutes. Turned out it was my 
application causing the issue and prompted me to write that post.

I haven't revisited that part of our internal app yet, so feel free to test 
and see what results you get.

Hopefully that is fixed and we can all be happy about it!

Steven
Studio LFP
http://www.studio-lfp.com


On Friday, September 30, 2011 3:16:57 PM UTC-5, Pinheiro wrote:

 Just to clarify one thing: 
  you don't want to use the requestLocationUpdates(). 
 I suppose you meant: you don't want to call requestLocationUpdates() 
 for continuous updates, right?In the BroadcastReceiver activity, I'll 
 call the requestLocationUpdates() and then removeUpdate() as soon as 
 there is a fix. Also, the new alarm will be created only after a fix 
 so that there isn't a possibility of alarm conflict (one alarm is not 
 done with the GPS and then there's a new one).

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Always-on GPS: widget or app?

2011-09-29 Thread Studio LFP
I tried to deal with this on an internal company app and you don't want to 
use the requestLocationUpdates().

See this bug I logged: 
http://code.google.com/p/android/issues/detail?id=5595

I'm not sure if that was a hardware driver or software, but I know you can 
reproduce that on plenty of hardware that is still around today.

A widget will only update every 30 minutes at the fastest via the system 
unless you have some sort of timer or alarm. It also doesn't wake up the 
phone to do the update, it delays it till the next phone wake.

Have you thought about trying a broadcast receiver coupled with an alarm?

If you need it to run if the phone is rebooted, just use an 
ACTION_BOOT_COMPLETED action in a receiver to start it (and don't forget the 
permission to receiver the boot message), then:

Intent iTimer = new Intent( com.yourcompany.yourapp.GET_GPS_LOCATION );
PendingIntent piTimer = PendingIntent.getBroadcast( context, 
BROADCAST_TIMER, iTimer,
PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT );

Time tAlarm = new Time();
tAlarm.setToNow();
tAlarm.minute = tAlarm.minute + 5;

AlarmManager amMgr = (AlarmManager)context.getSystemService( 
Context.ALARM_SERVICE );
amMgr.set( AlarmManager.RTC_WAKEUP, tAlarm.toMillis( false ), piTimer );

Please note that if you do use the AlarmManager.RTC_WAKEUP, it will keep 
waking the phone up every 5 minutes to fire off the requested intent. This 
means bad things for battery life.

In the manifest:

receiver android:name=.MyReceiver
intent-filter
action 
android:name=com.yourcompany.yourapp.GET_GPS_LOCATION/action
/intent-filter
/receiver

And of course the receiver:

public class MyReceiver extends BroadcastReceiver
{
@Override
public void onReceive( Context context, Intent intent )
{
if( intent.getAction().equals( 
com.yourcompany.yourapp.GET_GPS_LOCATION ) )
{
// Get your gps fix here and storage it however you'd like
// Reschedule the next alarm for 5 minutes from now using the 
code above.
}
}
}

I would just get the current fix and store it, then release the GPS so other 
people can use it. Then reset the alarm for 5 minutes from now. Now you 
don't need an active program to do something every so often and you don't 
have to worry about it being killed by the system.

You will want to request a WakeLock at the beginning of the receiver to make 
sure the phone will stay awake while you get the GPS location. Then just 
release the WakeLock at the end and let the phone go back to sleep.

Hope that helps.

Steven
Studio LFP
http://www.studio-lfp.com

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Always-on GPS: widget or app?

2011-09-29 Thread Pinheiro
That's exactly what I wanted to know, thanks a lot!

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en