0

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?

Qadir Ali
  • 58
  • 8

1 Answers1

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