![]() |
VOOZH | about |
An SOS mobile application is an emergency assistance app designed to help users quickly contact trusted people during dangerous or critical situations. These apps provide fast communication and safety features that can be triggered without manually operating the phone for a long time.
- Services,
- Runtime Permission Management,
- Populating ListView,
- Broadcast Receiver,
- Database Management in Android
Follow these steps to create a Mobile Application in Androide Studio.
Create a Contacts folder to manage all contact-related files used for storing and displaying emergency contacts in the ListView.
We create this class to store contact details like name and phone number in a structured format. It also ensures the phone number is properly validated before use.
We use this class to store and manage emergency contacts using SQLite database. It ensures contacts remain saved permanently even after app restart.
We create this to connect contact data with ListView for proper display. It also handles actions like showing and deleting contacts from the list.
We design this layout to define how each contact will look in the ListView. It improves UI by showing name and phone number in a structured format.
We create this module to handle background tasks like shake detection and SOS alerts. It ensures the app works even when it is not open.
We use this to detect device shaking using accelerometer sensor. It triggers SOS only when a specific shake pattern is detected.
We create this to run continuous background monitoring of shake events. It sends emergency SMS with location even if the app is closed.
If you start a service starts with the START STICKY return type, it will run in the background even if the host activity is not running in the foreground. If Android has to forcibly close a program due to a memory error or other reasons, the service will be restarted without the user's intervention.
In order to make the user aware that the Shake event has been registered or say the messages have been delivered, we create a vibrate() method. This will make the phone vibrate in a defined wave format.
We use FusedLocationProviderClient to get the user’s current location using getCurrentLocation(). It requires GPS/location services to be ON, otherwise it returns null. From Android O onwards, location access only works when the user explicitly enables location for privacy and awareness.
After getting the location successfully, we use SmsManager to send emergency messages to all saved contacts from the database. If location is not available, we send a fallback message without coordinates so receivers still get alert and can contact help or authorities for assistance.
Till now whatever we have done will work until the activity is in Foreground or Running. But what when the user kills the application? Or locks the phone? For this, we create a BroadcastReceiver.
Go to the MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file. Comments are added inside the code to understand the code in more detail.
Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file.
You can run app in 2 ways:
1. Emulator
2. Real Device (Recommended)
When app opens first time:
Allow all permissions:
Go to Settings if asked:
Output:
Notes:
1. Allow the app to autostart, in order to use the app while the screen is off.
2. Remove any battery optimization constraints on the app. This might make Android kill the service.
3. Allow all the permissions, especially allow location permissions by Allowing the app to use the device location all the time. This would allow the service to use the device location when the shake event is registered.