when i start a google maps navigation it keeps the screen alive and if i turn it off and on again with the power button, the maps app is above the lockscreen and only when i minimize the app, i have to unlock the screen. So i can turn the screen off and on and still use the app without having to unlock the screen
How can i achieve that for my own app?
I know i cann keep the screen on with
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
but that doesn't prevent me from having to unlock the screen after turning it off and on again.
You can use something like the screen pinning option . The application will be over the lock screen but it's not done programmatically, however it does the effect you want.
Instructions to pin an app on the screen:
However, if you want to do it with code, see the attribute : android:showOnLockScreen="true"
and the link :
您应该将getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
setContentView()
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
下面,并将android:keepScreenOn="true"
放入主布局的根视图中。
ok, thanks to the answer given by Arnauld Alex, i got it. Just add
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
before the setContentView(...)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.