Sep 30 | 7:55 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Sep 30 | 8:00 PM |
Swati D. | has entered the room |
Mark M. |
howdy!
|
Swati D. |
Hi
|
Swati D. |
Have a question about Android LBS..
|
Sep 30 | 8:05 PM |
Mark M. |
go ahead
|
Swati D. |
View paste
|
Swati D. |
This is a Question about getting current location of the device.-
|
Mark M. |
hold on -- phone call vame in
|
Mark M. |
er, came
|
Swati D. |
sure
|
Mark M. |
OK, I'm back
|
Mark M. |
1. I think the phone will not wake up
|
Mark M. |
B. Probably not
|
Mark M. |
Creating a WakefulLocationService is on my 18,000-item to-do list
|
Mark M. |
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
|
Sep 30 | 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
|
Mark M. |
now, you could try something tricky
|
Mark M. |
let's say you schedule requestLocationUpdates() for 1 hour from now
|
Swati D. |
ok
|
Swati D. |
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
|
Mark M. |
do that 5 minutes before you're hoping for a location fix
|
Mark M. |
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
|
Mark M. |
which is one of the reasons I really need to just go try and build the thing
|
Mark M. |
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
|
Mark M. |
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..
|
Sep 30 | 8:15 PM |
Mark M. |
it could be that service
|
Mark M. |
it could be something else
|
Mark M. |
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
|
Mark M. |
that's part of what I hope to solve, or at least wrap cleanly, with a WakefulLocationService
|
Mark M. |
your doWakefulWork() would get a Location along with an Intent
|
Mark M. |
I'd do the requestLocationUpdates() and the subsequent removeUpdates()
|
Mark M. |
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..
|
Sep 30 | 8:20 PM |
Swati D. |
Thanks!
|
Swati D. |
This chat facility is very useful
|
Swati D. |
Thanks for being available
|
Mark M. |
happy to help!
|
Mark M. |
particularly happy to help subscribers! :-)
|
Swati D. |
:)
|
Mark M. |
anything else I can help you with?
|
Swati D. |
one quick question..
|
Swati D. |
after certain event my service is supposed to send an email automatically...
|
Sep 30 | 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!
|
Swati D. |
Btw, I wrote a small service class which is
extending WakefulIntentService (from ur book) to get location updates
(using Alarm), and send sms/email..
|
Swati D. |
wondering if I can post the part of the code... if you have time to take a look..
|
Swati D. |
so see if my understanding is correct
|
Sep 30 | 8:30 PM |
Mark M. |
I wouldn't paste it in here
|
Mark M. |
probably too long
|
Mark M. |
if it's in a repo somewhere, you could post a link
|
Swati D. |
Not available online..
|
Swati D. |
Next time I will put it online :)
|
Mark M. |
Or use a GitHub gist, or a pastie.org page
|
Swati D. |
Thanks anyways
|
Swati D. |
oh
|
Swati D. |
so I just type code their and put link here? didn't know it works.. Let me try
|
Swati D. | |
Mark M. |
got it
|
Mark M. |
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
|
Mark M. |
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
|
Mark M. |
that's effectively what I need to do and get working as part of the WakefulLocationService
|
Sep 30 | 8:35 PM |
Swati D. |
hum.. Got it..
|
Swati D. |
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
|
Mark M. |
you register one on each location fix
|
Mark M. |
and I don't see you canceling it
|
Swati D. |
I do cancel it using - mgr.cancel(pi);
|
Mark M. |
oh, I see
|
Mark M. |
but then why are you using setInexactRepeating(), if you cancel it every time?
|
Mark M. |
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
|
Mark M. |
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
|
Mark M. |
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
|
Mark M. |
the alarm schedule is wiped on a reboot
|
Sep 30 | 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
|
Swati D. |
Yes. I am using that
|
Mark M. |
that's why I'm here!
|
Swati D. |
Thanks!
|
Swati D. |
I am for now..
|
Swati D. |
I will use acquire() and stuff. Will be gr8 if you get the service done.. I can use that then :)
|
Swati D. |
Thanks.
|
Swati D. | has left the room |
Sep 30 | 9:00 PM |
Mark M. | turned off guest access |