Office Hours — Today, September 30

Tuesday, September 28

Sep 30
7:55 PM
Mark M.
has entered the room
Mark M.
turned on guest access
8:00 PM
Swati D.
has entered the room
Mark M.
howdy!
Swati D.
Hi
Have a question about Android LBS..
8:05 PM
Mark M.
go ahead
Swati D.
View paste
I believe only way to do that is using requestLocationUpdates(....).

1. if I subscribe to requestLocationUpdates... with duration set to 1 hour and after 1 hour if my phone is sleeping (or during that 1 hour I rebooted my phone), does the listener still work? 

A. If yes... . After 1 hour, when I get update about location, I want to change duration to 2 hours. Is there a way to do that? If not, can I call removeUpdates, and immediately call requestLocationUpdates with duration as 2 hours?

B. If No... I was planning to set an alarm to go off after 1 hour, and call removeUpdates & requestLocationUpdates in the alarm receiver. (using WakefulIntentService from your book). Is that right strategy.
This is a Question about getting current location of the device.-
Mark M.
hold on -- phone call vame in
er, came
Swati D.
sure
Mark M.
OK, I'm back
1. I think the phone will not wake up
B. Probably not
Creating a WakefulLocationService is on my 18,000-item to-do list
the problem with WakefulIntentService and locations is that the locations are not immediately available, and IntentServices are meant to do their work and shut down
8:10 PM
Mark M.
(BTW, the answer to A is that your removeUpdates()/requestLocationUpdates() should work)
Swati D.
hum.. So if I am using requestLocationUpdates and if my phone is sleeping, my app will not get location udpate....right?
Mark M.
AFAIK, that is correct
now, you could try something tricky
let's say you schedule requestLocationUpdates() for 1 hour from now
Swati D.
ok
would using alarmservice work?
Mark M.
you could have a regular service be started with an alarm, grab a WakeLock, use a Timer/TimerTask to wait for 10 minutes, then release the WakeLock and shut down
do that 5 minutes before you're hoping for a location fix
hope that within that 10-minute window, the fix comes in
Swati D.
ok
Mark M.
a real WakefulLocationService could be more efficient, but getting that to work is probably going to be a bit tricky
which is one of the reasons I really need to just go try and build the thing
this keeps coming up
Swati D.
humm.. ok
Mark M.
I'll see if I can get some time late next week to try and take a shot at it
no promises, though
Swati D.
so from the regular service (that you mentioned above) I should be calling requestLocationUpdates... correct?
Mark M.
something needs to call requestLocationUpdates()
Swati D.
so do I need to call removeUpdates once I get location..
8:15 PM
Mark M.
it could be that service
it could be something else
once you get the location, you should removeUpdates() if you no longer need fixes
Swati D.
wondering since otherwise everytime "alarm" goes off, I will call requestLocationUpdates and not sure how it is from performance point of view
Mark M.
I have no good way of answering that
Swati D.
btw, is there any other way of getting current location other than calling requestLocationUpdate where I have to provide "duration for repeating".. I want location only once (when Alarm goes off)..
Mark M.
sorry, but particularly with GPS, requestLocationUpdates() is your best option, AFAICT
that's part of what I hope to solve, or at least wrap cleanly, with a WakefulLocationService
your doWakefulWork() would get a Location along with an Intent
I'd do the requestLocationUpdates() and the subsequent removeUpdates()
and if I find a better solution later on, I can switch to that without impacting anyone else's code
Swati D.
ok got it..
8:20 PM
Swati D.
Thanks!
This chat facility is very useful
Thanks for being available
Mark M.
happy to help!
particularly happy to help subscribers! :-)
Swati D.
:)
Mark M.
anything else I can help you with?
Swati D.
one quick question..
after certain event my service is supposed to send an email automatically...
8:25 PM
Swati D.
So in my app I am asking user to enter username and password of the gmail account they want email to be sent from. username ans password I am storing in shared preferences.. Wondering if there are any security issues with this?
Mark M.
If somebody loses their phone, and the person who finds it roots it, they'd get the users Gmail account info
Swati D.
I am using javamail library to send email.
Mark M.
Otherwise, it should be fairly safe
Swati D.
ok thats gr8.
Mark M.
you could lightly encrypt it, to force the thief to have to decompile your app to find out the encryption key
Swati D.
oh okay. Thats a gr8 idea. Thanks!
Btw, I wrote a small service class which is extending WakefulIntentService (from ur book) to get location updates (using Alarm), and send sms/email..
wondering if I can post the part of the code... if you have time to take a look..
so see if my understanding is correct
8:30 PM
Mark M.
I wouldn't paste it in here
probably too long
if it's in a repo somewhere, you could post a link
Swati D.
Not available online..
Next time I will put it online :)
Mark M.
Or use a GitHub gist, or a pastie.org page
Swati D.
Thanks anyways
oh
so I just type code their and put link here? didn't know it works.. Let me try
Mark M.
got it
that'll never work, at least in terms of the location stuff
Swati D.
why?
Mark M.
while you are requesting updates in doWakefulWork(), once that method returns, the device will fall back asleep
you would need to acquire() your own WakeLock in doWakefulWork(), the release() that WakeLock when you got the location and were ready for the device to fall asleep again
that's effectively what I need to do and get working as part of the WakefulLocationService
8:35 PM
Swati D.
hum.. Got it..
Thanks! I will try that.. Also, will be gr8 if you do it for us (subscribers) :)
Mark M.
also, it feels like you are going to have too many alarms
you register one on each location fix
and I don't see you canceling it
Swati D.
I do cancel it using - mgr.cancel(pi);
Mark M.
oh, I see
but then why are you using setInexactRepeating(), if you cancel it every time?
why not just use set()?
Swati D.
I was thinking what if the time alarm goes of phone doesn't have signal (or GPS visibility).. Then second alarm will help..
Mark M.
oh
interesting
Swati D.
if I set it only once, and something goes wrong, effectively my app will not work until person reboots the phone
Mark M.
right
there's something nagging at the back of my mind regarding what you're doing with the alarms there, but I can't quite put my finger on it
Swati D.
btw, if person reboots the phone, I need to set alarm again, right? I read that previously set alarm will not work after reboot
Mark M.
yes
the alarm schedule is wiped on a reboot
8:40 PM
Swati D.
Ok got it. Thanks!
Mark M.
that's why the book sample shows setting up the schedule via a BOOT_COMPLETED BroadcastReceiver
Swati D.
I am reading books, and writing this app. Doesn't have lot of experience with android.. Thanks for your help
Yes. I am using that
Mark M.
that's why I'm here!
Swati D.
Thanks!
I am for now..
I will use acquire() and stuff. Will be gr8 if you get the service done.. I can use that then :)
Thanks.
Swati D.
has left the room
9:00 PM
Mark M.
turned off guest access

Tuesday, September 28

 

Office Hours

People in this transcript

  • Mark Murphy
  • Swati D