1、修改frameworksasecore es esvaluesstrings.xml

 

  在此聲明幾個變數:

 

  < !-- 新增的螢幕休眠的item -->

 

  < string name="global_action_sleep">Sleep< /string>

 

  < !-- 新增sleep字串 -->

 

  < string name="sleep">Sleep< /string>

 

  < !-- 新增確認螢幕休眠資訊 -->

 

  < string name="sleep_confirm">The machine screen will turn off.< /string>

 

  2、修改frameworksasecorejavacomandroidinternalappShutdownThread.java

 

  要引用幾個包

 

  import android.os.SystemClock;

 

  android.os.PowerManager;

 

  //添加螢幕待機方法

 

  public static void goToSleep(Context context,long time){

 

  context.enforceCallingOrSelfPermission(android.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.internal.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_SERVICE);

 

  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();

 

  }

 

  3、修改 frameworkspoliciesasemidcomandroidinternalpolicyimplGlobalActions.java

 

  找到mItems = Lists.newArrayList,原始代碼中定義了兩個SinglePressAction,即為power按鈕的功能表項目,這時要在裡面
增加一個SinglePressAction實現螢幕休眠功能的按鈕,仿照原始代碼

  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;

  }

  }

  修改後重新編譯,耐心等待後,在android-x86平臺的平板電腦上測試可以實現電腦的休眠功能

  注:轉載本blog請注明http://blog.sina.com.cn/hylinblog
創作者介紹
創作者 shadow 的頭像
shadow

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()