How to programmatically lock screen in Android? [duplicate]

Check this class : com.android.internal.policy.impl.LockScreen Referenced from here: Can you lock screen from your app? Also check code for enabling and disabling lock Screen in Android. (Referenced from here) 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()

How can i set up screen lock with a password programmatically?

Use this code in your App, it works for me: DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); ComponentName demoDeviceAdmin = new ComponentName(this, name of activity); devicePolicyManager.setPasswordQuality( demoDeviceAdmin,DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED); devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, 5); boolean result = devicePolicyManager.resetPassword(“123456”, DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY); Toast.makeText(this, “button_lock_password_device…”+result, Toast.LENGTH_LONG).show();

A way to get unlock event in android?

There is a Broadcast Receiver Action ACTION_USER_PRESENT here is the implementation of ACTION_USER_PRESENT and ACTION_SHUTDOWN add this to your application Manifests <receiver android:name=”.UserPresentBroadcastReceiver”> <intent-filter> <action android:name=”android.intent.action.USER_PRESENT” /> <action android:name=”android.intent.action.ACTION_SHUTDOWN” /> </intent-filter> </receiver> to receive the actions import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class UserPresentBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context arg0, Intent intent) … Read more

Preventing status bar expansion

You can actually prevent the status bar from expanding, without rooting phone. See this link. This draws a window the height of the status bar and consumes all touch events. Call the following code just after onCreate(). public static void preventStatusBarExpansion(Context context) { WindowManager manager = ((WindowManager) context.getApplicationContext() .getSystemService(Context.WINDOW_SERVICE)); Activity activity = (Activity)context; WindowManager.LayoutParams localLayoutParams … Read more

Creating custom LockScreen in android [closed]

Another way to develop a LockScreen App is by using Views, let me explain it. First of all you can “disable” in some devices the System lock screen by disabling the KEYGUARD: ((KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE)).newKeyguardLock(“IN”).disableKeyguard(); You should put this line of code in your Service. After that you can launch an activity every time the screen goes … Read more