歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android系統添加手機重啟reboot選項

Android系統添加手機重啟reboot選項

日期:2017/3/1 10:25:53   编辑:Linux編程

都是修改framework下面的文件:

1、com.Android.internal.policy.impl.GlobalActions

在items中添加如下參考代碼,表示在系統power菜單中添加一個“重啟”選項以及響應reboot事件:

  1. new SinglePressAction(
  2. com.android.internal.R.drawable.ic_lock_power_off,
  3. R.string.global_action_power_reboot) {
  4. public void onPress() {
  5. ShutdownThread.reboot(mContext, null, true);
  6. }
  7. public boolean showDuringKeyguard() {
  8. return true;
  9. }
  10. public boolean showBeforeProvisioning() {
  11. return true;
  12. }
  13. });

2、 在com.android.internal.app.ShutdownThread類中添加相應的重啟reboot處理事件。

類似於下面的代碼:

  1. /**
  2. * Request a clean shutdown, waiting for subsystems to clean up their
  3. * state etc. Must be called from a Looper thread in which its UI
  4. * is shown.
  5. *
  6. * @param context Context used to display the shutdown progress dialog.
  7. * @param confirm true if user confirmation is needed before shutting down.
  8. * @param isReboot true if user confirmation is needed reboot and not shutdown.
  9. */
  10. public static void shutdown(final Context context, boolean confirm,boolean isReboot) {
  11. mReboot = isReboot ;
  12. // ensure that only one thread is trying to power down.
  13. // any additional calls are just returned
  14. synchronized (sIsStartedGuard) {
  15. if (sIsStarted) {
  16. Log.d(TAG, "Request to shutdown already running, returning.");
  17. return;
  18. }
  19. }
  20. Log.d(TAG, "Notifying thread to start radio shutdown");
  21. if (confirm) {
  22. final AlertDialog dialog = new AlertDialog.Builder(context)
  23. .setIcon(android.R.drawable.ic_dialog_alert)
  24. .setTitle(mReboot?com.android.internal.R.string.global_action_power_reboot:com.android.internal.R.string.global_action_power_off)
  25. .setMessage(mReboot?com.android.internal.R.string.reboot_confirm:com.android.internal.R.string.shutdown_confirm)
  26. .setPositiveButton(com.android.internal.R.string.yes, new DialogInterface.OnClickListener() {
  27. public void onClick(DialogInterface dialog, int which) {
  28. beginShutdownSequence(context);
  29. }
  30. })
  31. .setNegativeButton(com.android.internal.R.string.no, null)
  32. .create();
  33. dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
  34. if (!context.getResources().getBoolean(
  35. com.android.internal.R.bool.config_sf_slowBlur)) {
  36. dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
  37. }
  38. dialog.show();
  39. } else {
  40. beginShutdownSequence(context);
  41. }
  42. }

更多Android相關信息見Android 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=11

Copyright © Linux教程網 All Rights Reserved