سؤال

Is it possible to turn-off the display programmatically in android? I would like to have a button that when pressed switches the display off. Is it possible? If so, how?

هل كانت مفيدة؟

المحلول

You can try doing the following:

DevicePolicyManager mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
mDPM.lockNow();

That will lock your phone (same as pressing the power/lock button) and thus turn of the screen.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top