1. Modify/frameworks/base/core/res/res/values/strings.xml
Declare several variables here:
<!--New screen-sleeping item-->
<string name= "Global_action_sleep" >Sleep</string>
<!--add a sleep string-->
<string name= "Sleep" >Sleep</string>
<!--new Confirmation screen hibernate information-->
<string name= "sleep_confirm" >the machine screen would turn off.</string>
2. Modify/frameworks/base/core/java/com/android/internal/app/shutdownthread.java
To refer to a few packages
Import Android.os.SystemClock;
Android.os.PowerManager; Add screen standby method public static void Gotosleep (context Context,long time) {context.enforcecallingorselfpermission Droid.
Manifest.permission.DEVICE_POWER, NULL); Final Alertdialog Dialog = new Alertdialog.builder (context). SetIcon (Android. R.drawable.ic_dialog_alert). Settitle (Com.android.internal.r.string.sleep). Setmessage (Com.android.interna
l.r.string.sleep_confirm). Setpositivebutton (Com.android.internal.r.string.yes,
New Dialoginterface.onclicklistener () {public void OnClick (dialoginterface dialog, int which) {PowerManager pm = (powermanager) mcontext.getsystemservice (context.power_ser
VICE);
Pm.gotosleep (Systemclock.uptimemillis ()); }). Setnegativebutton (com.android.internal.r.string.no, NULL)
. Create ();
Dialog.getwindow (). SetType (WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
Dialog.getwindow (). Addflags (WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
Dialog.show (); }
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/
3. Modify/frameworks/policies/base/mid/com/android/internal/policy/impl/globalactions.java
Find Mitems = lists.newarraylist, the original code defines two singlepressaction, that is, the Power button menu item, then in the inside
Add a Singlepressaction button that implements the screen hibernate function, imitating the original code
New Singlepressaction (Com.android.internal.r.drawable.ic_lock_power_off,
r.string.global_action_sleep) { Public
void Onpress () {
shutdownthread.gotosleep (Mcontext,systemclock.uptimemillis ());
}
public Boolean Showduringkeyguard () {return
true;
}
public Boolean showbeforeprovisioning () {return
true;
}
}
After the revision, the patient waits, in the Android-x86 platform's tablet computer test can realize the computer the hibernation function
NOTE: Reprint this blog please specify Http://blog.sina.com.cn/hylinblog