I build a simple application to test the sleep option of the android mobile
I put this code inside the button:
Intent lockscreen=new Intent();
lockscreen.setAction(Intent.ACTION_SCREEN_OFF);
startActivity(lockscreen);
with no change ,
also I put the permission…I want when I press this button my phone would locked (not locked by password) (normal lock)
Any Help.
First,
ACTION_SCREEN_OFFis a broadcastIntent, not one used withstartActivity().Second, as the documentation for
ACTION_SCREEN_OFFstates, “This is a protected intent that can only be sent by the system”.You are welcome to use the device admin APIs and use
lockNow()onDevicePolicyManager, which should achieve this effect.