时间:2021-01-30 10:22:51 | 栏目:Android代码 | 点击:次
本文实例讲述了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相关内容感兴趣的读者可查看本站专题:《Android开发入门与进阶教程》、《Android调试技巧与常见问题解决方法汇总》、《Android基本组件用法总结》、《Android视图View技巧总结》、《Android布局layout技巧总结》及《Android控件用法总结》
希望本文所述对大家Android程序设计有所帮助。