0

I hope this question wasn´t asked before, but I couldn´t find any solution for my problem. I have a widget which is also used for keyguard. I want to add an onClick handler for my widget. There is no problem, when the widget is on home-screen, the activity starts normally. But on keyguard the activity is launched, but isn´t shown, because the device is locked.

I don´t want to dismiss the keyguard with flags like WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED and WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD. I just want a little window to be shown, where I am asked to unlock the device, like it is opened when you click on several keyguard widgets, like for the android e-mail application.

Is there another flag to achieve this? Or do I have to do something with my intent, called to open the activity? Thanks for help.

Erich
  • 1,838
  • 16
  • 20

1 Answers1

0

For enabling or disabling lock screen in Android, we need to get the instance of keyBoard Manager, using getSystemService(). The syntax is as,

KeyguardManager keyguardManager = 
    (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE);  
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);  

For locking the screen use,

lock.reenableKeyguard();

and for disabling the lock use,

lock.disableKeyguard();  

This will just hide the lock screen and will display if any incoming call or any such event is happening, it will display that screen. It wont display the lock screen.

When running the application, to disable from going to the lock state, just use setKeepScreenOn() is set to true. or use the xml attribute android:keepScreenOn="true"

Another way to prevent the device to go to the sleep or lock mode when the application is running is set this api to true - setKeepScreenOn()

And of course we need to give permission android.permission.DISABLE_KEYGUARD

Anders R. Bystrup
  • 15,729
  • 10
  • 59
  • 55
suba
  • 69
  • 5