android手机有很多的第三方固件,其中有不少固件中有reboot的功能,这个功能是如何实现的呢?我这里会做一个简单的示例。先看一个效果图吧!
?
?
如图在dialog中的最后一项是reboot功能。下面看看代码是怎么修改的:
文件路径:?frameworks/policies/base/phone/com/android/internal/policy/impl/GlobalActions.java? ?
private?AlertDialog createDialog() {?
????????....?
????????mItems = Lists.newArrayList(?
????????????????// silent mode?
????????????????mSilentModeToggle,?
????????????????// next: airplane mode?
????????????????mAirplaneModeOn,?
????????????????// last: power off?
????????????????new?SinglePressAction(?
????????????????????????com.android.internal.R.drawable.ic_lock_power_off,?
????????????????????????R.string.global_action_power_off) {?
????????????????????public?void?onPress() {?
????????????????????????// shutdown by making sure radio and power are handled accordingly.?
????????????????????????ShutdownThread.shutdown(mContext,?true?);?
????????????????????}?
????????????????????public?boolean?showDuringKeyguard() {?
????????????????????????return?true?;?
????????????????????}?
????????????????????public?boolean?showBeforeProvisioning() {?
????????????????????????return?true?;?
????????????????????}?
????????????????},?
??????????????// this is add code?
??????????????// last: reboot?
??????????????new?SinglePressAction(?
????????????????????com.android.internal.R.drawable.ic_lock_power_off,?
????????????????????R.string.global_action_reboot) {?
????????????????????public?void?onPress() {?
????????????????????????// shutdown by making sure radio and power are handled accordingly.?
????????????????????????ShutdownThread.reboot(mContext,?""?,?true?);?
????????????????????}?
????????????????????public?boolean?showDuringKeyguard() {?
????????????????????????return?true?;?
????????????????????}?
????????????????????public?boolean?showBeforeProvisioning() {?
????????????????????????return?true?;?
????????????????????}?
????????????????});?
????????mAdapter =?new?MyAdapter();?
????????....?
????????return?dialog;?
????}
??????代码中ShutdownThread.reboot()方法有三个参数其中第二个参数是一个String,如果这个String是NULL的话,就是正常重启,如果是recovery,系统重启进入recovery mode。R.string.global_action_reboot是我在系统资源文件中添加的字符串。呵呵是不是很简单啊!
转自:?http://blog.csdn.net/yuanfeng5721/archive/2011/02/25/6207290.aspx