android 加入关屏

引用:http://blog.csdn.net/hmg25/article/details/6203160

修改policies/base/phone/com/android/internal/policy/impl/PhoneWindowManager.java
添加个关屏菜单。其实如果硬件能定义一个专门关机的键会比较好 长短按有区别的对待。挂断短按如果要关屏的话 就要加入电话判断是不是通话?
 
修改frameworks/base/core/java/com/android/internal/app/ShutdownThread.java添加关屏代码

import android.os.SystemClock;
import 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();
     
      }

你可能感兴趣的:(android)