本文实例讲述了Android 6.0开发实现关机菜单添加重启按钮的方法。分享给大家供大家参考,具体如下:
修改:
/trunk/LINUX/android/frameworks/base/core/res/res/values/config.xml
添加数组name为config_globalActionsList的值
修改:
/LINUX/android/frameworks/base/services/core/java/com/android/server/policy/GlobalActions.java
添加变量:
private static final String GLOBAL_ACTION_KEY_USERS = "users"; private static final String GLOBAL_ACTION_KEY_SETTINGS = "settings"; private static final String GLOBAL_ACTION_KEY_LOCKDOWN = "lockdown"; private static final String GLOBAL_ACTION_KEY_REBOOT = "reboot";
在 private GlobalActionsDialog createDialog()内添加:
if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) { mItems.add(new PowerAction()); } else if (GLOBAL_ACTION_KEY_REBOOT.equals(actionKey)) { mItems.add(new RebootAction()); } else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) { mItems.add(mAirplaneModeOn); } else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) { if (Settings.Global.getint(mContext.getContentResolver(), Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserOwner()) { mItems.add(getBugReportAction()); } }
在空白处添加:
private final class RebootAction extends SinglePressAction { private RebootAction() { super(com.android.internal.R.drawable.ic_lock_power_reboot, R.string.global_action_reboot); } @Override public Boolean showDuringKeyguard() { return true; } @Override public Boolean showBeforeProvisioning() { return true; } @Override public void onPress() { try { IPowerManager pm = IPowerManager.Stub.asInterface(ServiceManager.getService(Context.POWER_SERVICE)); pm.reboot(true, null, false); } catch (RemoteException e) { Log.e(TAG, "PowerManager service died!", e); return; } } }
结束
需要编译以下目录
/trunk/LINUX/android/frameworks/base
/trunk/LINUX/android/frameworks/res
希望本文所述对大家Android程序设计有所帮助。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:notice#nhooo.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。