Sometimes it pays to read through the Developer group discussion. They
do a lot with MediaPlayer currently, and I saw a related topic to
services just today:
http://groups.google.com/group/android-developers/browse_frm/thread/bef63c1d572673a3/be02eb559ef67e95#be02eb559ef67e95
hackbod explains how one should do it:
No service should remain in the memory for all time.
"Instead, you can use the alarm manager to schedule a
receiver at the desired schedule, and when the receiver is launched
start your service to do the check (and then it can stop itself). "
The same can obviously be done with the ProximityAlert.
Further below:
"(Btw, in an upcoming SDK you will be able to have the alarm manager
directly start a service without needing the intermediate broadcast
receiver.) "
and I think the same will be available for Proximity Alert.
I doubt that the upcoming SDK will be in time before the deadline, so
we should start from what we have, and that is m5-rc15.
From this information it is clear that it would not be very
advantageous to use aidl for this purpose.
I would really opt for building something around
Locationmanager.addProximityAlert, rather than coding this
functionality by hand.
http://code.google.com/android/reference/android/location/LocationManager.html#addProximityAlert(double,%20double,%20float,%20long,%20android.content.Intent)
Google will surely optimize this routine for battery saving, and it
will work optimally with different location providers, like GPS,
CELL_ID, ...
Although I have not tried it, I'm quite confident that you can pass
several intents (that may differ by parameters given) to set several
"hot spots", so that each intent is fired when you are close to a
place.
1) So, the simplest to try out would be to use intent with
VIEW_ACTION, and some content URI. Your Intent should open at the
desired location. (Note that expiration=-1 does not work due to the
bug mentioned in the other thread, but a very large number works (it
is in milliseconds!))
2) If this works, write an intent receiver that receives the intent
and fires a notification. Somehow one would have to pass the data
which text to display in the notification and the intent to be fired
when the user clicks on the notification along with the original
intent to addProximityAlert.
3) Even more abstract: Add a new ContentProvider that stores all
ProximityAlerts. Android's LocationManager allows to add and remove
ProximityAlerts, but not to view them. So if you want to edit the
alerts, they would have to be stored somewhere else:
e.g.
content://org.openintents.locations/alerts/123
where alerts corresponds to a table (the list of locations that you
mentioned in your post)
double latitude, double longitude, float radius, long expiration,
Intent intent, String notificationText
Now, your IntentReceiver waits for .../alerts/*, and when one arrives,
it can look up the content provider for the notificationText and the
"true" intent to be fired.
So, actually, for this you don't need to implement a service. A
receiver that pops up the notification will be fine enough.
Does this make sense?
Hm, another possibility may be to have a general alert provider:
content://org.openintents.alerts/locations/123
then one could also have
content://org.openintents.alerts/alarms/43
so there could be alerts connected to location or to alarms. (later
also: alerts/people - to be fired when a certain person calls, or an
sms from a certain person arrives.)
So, what do you think about this ContentProvider?
Peli