I'm going to make an Android lock screen app. If you turn the screen off and on, you have to display the lock screen, so when the screen turns off, you want to display the lock screen app in advance and make the lock screen visible when the screen turns on. I want to do an event or an alarm when the screen is turned off? What should I do?
android
There's something called Android ACTION_SCREEN_OFF that tells you to turn off the screen.
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
intentFilter.addAction(Intent.ACTION_SCREEN_ON);
BroadcastReceiver screenOnOff = new BroadcastReceiver()
{
public static final String ScreenOff = "android.intent.action.SCREEN_OFF";
public static final String ScreenOn = "android.intent.action.SCREEN_ON";
public void onReceive(Context contex, Intent intent)
{
if (intent.getAction().equals(ScreenOff))
{
Log.e("MainActivity", "Screen Off");
}
else if (intent.getAction().equals(ScreenOn))
{
Log.e("MainActivity", "Screen On");
}
}
};
registerReceiver(screenOnOff, intentFilter);
I think you can register your broadcast like this and take care of it properly on ScreenOff.
774 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
553 GDB gets version error when attempting to debug with the Presense SDK (IDE)
554 Understanding How to Configure Google API Key
554 Uncaught (inpromise) Error on Electron: An object could not be cloned
554 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.