Android Unlock screen and open camera from activity

833 Views Asked by At

I am developing an app which has a background service running and after some interval I want to take a picture from the camera. When the device is locked, I want to unlock the screen to open my camera activity.

1

There are 1 best solutions below

0
On

You can unlock the screen by:

KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
if (keyguardManager.inKeyguardRestrictedInputMode()) 
{
    Window window = Activity.getWindow();
    window.addFlags(LayoutParams.FLAG_DISMISS_KEYGUARD);
    window.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    window.addFlags(LayoutParams.FLAG_TURN_SCREEN_ON);
} 

The KeyguardManager is first used to check whether it is locked.