Android Question how to press power button programmatically

toby

Well-Known Member
Licensed User
Longtime User
I'm working on an app which will simulate the pressing of the power button from time to time. I'm wondering how.

Thanks in advance for any helps!
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
sorry, I meant the physical button used to turn on and off your phone.
Could you describe a little more your need ? Is it to light the screen or really send the Power intent ?
 
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime User
Some Java examples, but i don't know how to implement it:
http://stackoverflow.com/a/5440790
from: https://developer.android.com/guide/topics/admin/device-admin.html#top
Set device lock
You can set the maximum period of user inactivity that can occur before the device locks. For example:

DevicePolicyManager mDPM;ComponentName mDeviceAdminSample;...long timeMs =1000L*Long.parseLong(mTimeout.getText().toString());
mDPM.setMaximumTimeToLock(mDeviceAdminSample, timeMs);

You can also programmatically tell the device to lock immediately:
DevicePolicyManager mDPM;
mDPM.lockNow();
 
Upvote 0
Top