how to make application in android studio that work while mobile is locked. suppose in any emergency situation if the user swipe on mobile or press lock button 2 times it will send its location to the saved emergency numbers while mobile is locked. Any Idea?
Asked
Active
Viewed 62 times
0
-
Some of the ideas in https://stackoverflow.com/questions/17260986 might answer your question. – Stephen C Jun 06 '21 at 02:22
1 Answers
0
Since your application is not in use and you want to listen to some specific event and perform a specific task, you should use a Service
. You can create a LockService
as explained in this answer.
https://stackoverflow.com/a/30030372/4491971
Instead of starting activity as explained in that answer, you can write your operation for sending the location to the saved emergency numbers.
package com.example.userpresent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
public class ScreenReceiver extends BroadcastReceiver {
public static boolean wasScreenOn = true;
@Override
public void onReceive(final Context context, final Intent intent) {
if(intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {
// YOUR OPERATION CAN BE DONE HERE
}
}
}

Mohit Ajwani
- 1,328
- 12
- 24