I want to perform some calculations while the phone is in locked screen mode, regardless if the app is on the foreground or the background.
I know that in order to do this, I need to use OnObscured event from App class. However, it is only launched when the app is in the foreground, but not in the background.
So, I would like to know if exist any way to detect the phone state while the App runs the background.
I have thought something that would be crazy, but is to access an API property which is not allowed to use while the phone is in locked screen, and then catch the exception and, with that, get if the phone is active or sleeping.
I am open to hear new ideas.
I figured out a simple thing - maybe it will help you:
I assume that you already disabled Idle Detection to run your calculations in background.
So why not to create the variable in which you hold the state of the App? Since you have to launch first your App, so it goes to foreground and when Obscured is called and IsLocked = true, set the variable. Then you can check it whenever you want: