I want broadcast to start an activity even when the phone is locked. What I have found is that there are window flags FLAG_SHOW_WHEN_LOCKED and FLAG_TURN_SCREEN_ON that do exactly what I need. The problem is that they are deprecated in the latest versions of android.
Also I found out that setShowWhenLocked(true) and setTurnScreenOn(true) methods can be used but they give me an error "No virtual method setShowWhenLocked(Z)V in class Someclass"
Could you suggest how I could achieve the needed outcome?
Use activityObj.setShowWhenLocked (true)
instead of FLAG_SHOW_WHEN_LOCKED
Use setTurnScreenOn()
instead of FLAG_TURN_SCREEN_ON
Note: These methods are only available from API level 27. So you need to perform some checking prior to using it
if (Build.VERSION.SDK_INT >= 27) {
setShowWhenLocked(true)
setTurnScreenOn(true)
} else {
this.window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With