This is Part 1 of a three-part four-part series Developing Proximity Alerts for Mobile Applications using the Android Platform. Please click appropriately if you are looking for Part 2, Part 3, or the bonus Part 4 that discusses important new enhancements.
We’ve all used Event Reminders as a way to remind ourselves of important events. These reminders are time triggered, that is, our reminders are activated at a specific time in the future. Birthdays, meetings, time to pay the bills are all examples of Event Reminders.
But let’s say you don’t know the specific time of an event, but would like to be reminded, or alerted, of the event when you are actually at a particular place. For example, Grandma’s garbage disposal is broken, and you will fix it the next time you go to her house. And say you don’t know the next time you are coming over, but would benefit from an alert that is activated when you actually arrive at her house.
Another example is activating an alert that lists some items to pick up the next time you are at the grocery store.
The good news is now we can generate these alerts using our Android-based smart phones. This is specifically known as proximity alerts, and is the topic of this post. We will discuss how the LocationManager class helps us in this endeavor. We will also create a ProximityIntent based on the PendingIntent. And we will create a ProximityIntentReceiver by extending the BroadcastReceiver in order to receive the proximity intents.
In this post, we will develop a Proximity Alert Mobile Application using the Android Platform. The final application will look like the following:
And we will use the following screen to add proximity alerts:
Let’s Get Started
To build a Proximity Alert Mobile Application allowing users to set and receive alerts based on location proximity, similar to setting and receiving traditional time-based event reminders.
- To set one or more location proximity alert(s), configurable by location, radius of proximity (in meters), and expiration date/time
- To insert/edit freestyle attributes to the location proximity alerts, e.g., todo list, grocery list, etc…
- To be notified (that is, alerted) when the user enters the location within configured proximity parameters
- To delete one, or all, proximity alert(s)
- In order to “set” a location proximity alert, it is necessary to actually take the smart phone to the location being targeted and “set” the alert
- We will need to create both proximity configuration and proximity alert screens
- We will register the application as a “service” in order to run it in the background
- User Interface style is a low priority! Also known as lazy author!
Before we start cutting code, we need to think through our design. As a minimum, we need the following:
- Home View – all actions start from this screen, and display our active list of proximity alerts
- Proximity Alert View – this will allow us to add/edit/delete proximity alerts
- Proximity Alert Entity – represents a single alert, and functions like a DTO
- Proximity Alert Repository – this will provide persistent storage of our alerts
- Proximity Alert Notification View – notifies of a proximity alert, i.e., displays an alert screen when an actual alert is fired
- Proximity Intent Receiver – this is our Broadcast Receiver (more on this later)
- Settings “Preferences” View – we will use Android’s PreferenceActivity to edit common configuration settings, e.g., proximity radius
Ask anyone who has been around the block creating Android applications, and they will tell you to make sure your AndroidManifest.xml file is set up properly. All Activities referenced by your application, additional libraries used by your application, and all necessary permissions must be set up in this in order for your application to work properly.
With that said, our manifest file is as follows:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="iqspike.proximityalert.activity" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <uses-library android:name="com.google.android.maps"/> <activity android:name=".ProximityAlertHomeActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="ProximityAlertActivity"> </activity> <activity android:name="ProximityAlertSetActivity"> </activity> <activity android:name="ProximityAlertPreferencesActivity"> </activity> </application> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.VIBRATE"/> </manifest>
Note the highlighted lines near the bottom indicating the INTERNET, ACCESS_FINE_LOCATION, and VIBRATE permissions we require. Note that ACCESS_FINE_LOCATION is a bit more battery intensive than ACCESS_COARSE_LOCATION, but is necessary when you need a finer level of GPS information.
We’re just getting started. Please see Part 2 as we start cutting code for our Mobile Proximity Alert Application using the Android Platform!
More coming soon!