0

I am working on a drone app where I need to land the drone when the phone screen in locked. I have tried KeyguardManager but its deprecated. Are there any other functions or methods which I can use?

compileSdkVersion 29

buildToolsVersion "29.0.2"

minSdkVersion 15

targetSdkVersion 29

I have already included onPause method in my code

@Override

    protected void onPause() {

        // Code to land
        super.onPause();
    }
Wang Liang
  • 4,244
  • 6
  • 22
  • 45
Sarath
  • 89
  • 2
  • 9

1 Answers1

0

you can determine whether screen is off or not by using PowerManager . like follow .

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
boolean isScreenOn = pm.isInteractive();

although you might see something like this insted pm.isInteractive()

boolean isScreenOn = pm.isScreenOn();

which depracted in api 21 . i hope this work . for more detail you can visit documentation here . Documentation

Kiran Patel
  • 98
  • 3
  • 12