23

I am looking for a way to replace the stock lock screen (with an app, not a rom). What is the best way to do it, for a start to disable the lock screen on as much devices as possible? Thanks!

gbox
  • 779
  • 1
  • 5
  • 20
  • You can read a discussion about this here: http://groups.google.com/group/android-developers/browse_thread/thread/f66dfab6c300eb6f/f9bc83e8eef1e2d4?pli=1 – Macarse Jan 16 '11 at 13:19

4 Answers4

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

in androidmanifest:

<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
PravinDodia
  • 3,201
  • 1
  • 16
  • 22
Mitul Nakum
  • 5,364
  • 5
  • 33
  • 41
  • 6
    The class KeyguardLock has been deprecated. Setting the window flags as shown by @hsgubert below seems the current way to turn off the key guard/lock screen. – pstoppani Feb 01 '13 at 00:48
  • 1
    Perfect. Thank you. Have been looking for this from last 3 days :) – Arshad Jul 10 '15 at 16:29
34

You can just use this line in the activity:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
hsgubert
  • 2,256
  • 1
  • 19
  • 23
5

Try this, it will keep awake the screen/ display , as long as the activity is on top.

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Also this does not require any permission in manifest.

Swapnil Kale
  • 2,090
  • 1
  • 21
  • 21
2

Check out this link http://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents/

listen to the screen on intent and I guess just launch your lock screen.

Faisal Abid
  • 8,442
  • 14
  • 56
  • 90