Add a device auth before shutting down the device without unlock

Viewed 29

Hey guys I have an app that has an antitheft feature called AnitPowerOff, this feature needs to stop the user from shutting down the phone while in the locked state. Actually there is a CountDownTimer that times out and then the app locks the device. So I have this Samsung Galaxy A10 smartphone and it whenever I lock the screen and then try to shut down after I click the shut down button then it requires a password. Is there a way of programatically achieving this with Android Java. I have tried using a BroadcatReceiever but the app goes off and does not give the app time to execute the ode inside OnReceive. Here is the BroadcastReceiver attempt. I need to use a service that listens on shutdown events.

 public class ShutdownReceiver : BroadcastReceiver
    {
       
        public override void OnReceive(Context context, Intent intent)
        {
            if (intent.Action == Intent.ActionShutdown)
            {
                Toast.MakeText(context,"Your trying to shut down the device",ToastLength.Long).Show();
                //require some form of pattern from the device
            }
        }
    }

The code is in C# but any Java code is welcome as I can easily convert it to C# for Xamarin Android. Is there a way to start a service that will capture when the shutdown button is clicked and then before the action goes through we tell the system to require password from the user?

0 Answers
Related