android设备添加F1-F12按键功能


2012-04-26 14:23:48|  分类: android|字号 订阅

一、首先在android4.0\frameworks\base\data\keyboards\(qwerty.kl)Generic.kl文件中做如下改变:

key 59   HOME
key 60   FUNCTION_F2
key 61   FUNCTION_F3
key 62   FUNCTION_F4
key 63   FUNCTION_F5
key 64   EXPLORER
key 65   FUNCTION_F7
key 66   FUNCTION_F8
key 67   MENU
key 68   POWER             WAKE
key 87   FUNCTION_F11
key 88   FUNCTION_F9

 

这样F1键就是回到Home界面;

     F6键就是打开浏览器;

     F9键就是打开/关闭菜单;

     F10键就是关闭屏幕

二、然后修改android4.0\frameworks\base\policy\src\com\android\internal\policy\impl\PhoneWindowManager.java

在interceptKeyBeforeDispatching()方法的final boolean canceled = event.isCanceled();后面中 增加如下代码:

if ((keyCode == KeyEvent.KEYCODE_FUNCTION_F3) && !down) {
            //setDisplayOutput();
  Intent intent3 = new Intent();
  ComponentName cn3 = new ComponentName("com.cooliris.media", "com.cooliris.media.Gallery");
  intent3.setComponent(cn3);
  intent3.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  intent3.setAction("android.intent.action.MAIN");
  mContext.startActivity(intent3);
  }
  
        if ((keyCode == KeyEvent.KEYCODE_FUNCTION_F4) && !down) {
            //setDisplayOutput();
  Intent intent4 = new Intent();
  ComponentName cn4 = new ComponentName("com.android.camera", "com.android.camera.Camera");
  intent4.setComponent(cn4);
  intent4.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  intent4.setAction("android.intent.action.MAIN");
  mContext.startActivity(intent4);
  }
  
  if ((keyCode == KeyEvent.KEYCODE_FUNCTION_F5) && !down) {
            //setDisplayOutput();
  Intent intent5 = new Intent();
  ComponentName cn5 = new ComponentName("com.android.music", "com.android.music.MusicBrowserActivity");
  intent5.setComponent(cn5);
  intent5.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  intent5.setAction("android.intent.action.MAIN");
  mContext.startActivity(intent5);
  }
  
  if ((keyCode == KeyEvent.KEYCODE_FUNCTION_F7) && !down) {
            //setDisplayOutput();
  Intent intent7 = new Intent();
  ComponentName cn7 = new ComponentName("com.android.settings", "com.android.settings.Settings");
  intent7.setComponent(cn7);
  intent7.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  intent7.setAction("android.intent.action.MAIN");
  mContext.startActivity(intent7);
  }
  
  if ((keyCode == KeyEvent.KEYCODE_FUNCTION_F11) && !down) {
            //setDisplayOutput();
  Intent intent8 = new Intent();
  ComponentName cn8 = new ComponentName("com.android.calculator2", "com.android.calculator2.Calculator");
  intent8.setComponent(cn8);
  intent8.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  intent8.setAction("android.intent.action.MAIN");
  mContext.startActivity(intent8);
  }
  
  if ((keyCode == KeyEvent.KEYCODE_FUNCTION_F9) && !down) {
            //setDisplayOutput();
   WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
   if (wifiManager.isWifiEnabled()) {  
    wifiManager.setWifiEnabled(false);  
   } else {  
   wifiManager.setWifiEnabled(true);  
   }
  }
  
  if ((keyCode == KeyEvent.KEYCODE_FUNCTION_F8) && !down) {
            //setDisplayOutput();
  Intent intent11 = new Intent();
  ComponentName cn11 = new ComponentName("com.estrongs.android.pop", "com.estrongs.android.pop.view.FileExplorerActivity");
  intent11.setComponent(cn11);
  intent11.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  intent11.setAction("android.intent.action.MAIN");
  mContext.startActivity(intent11);
  }
 if ((keyCode == KeyEvent.KEYCODE_FUNCTION_F2) && !down){
   Intent intent2 = new Intent();
   ComponentName cn2 = new ComponentName("com.android.apkmanager", "com.android.apkmanager.MainActivity");
   intent2.setComponent(cn2);
   intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   intent2.setAction("android.intent.action.MAIN");
   mContext.startActivity(intent2);
  }

三、F1返回到home也可以如下定义

(KeyEvent在android4.0\frameworks\base\core\java\android\view\KeyEvent.java下面定义)

 在interceptKeyBeforeQueueing方法中switch (keyCode)添加

            case KeyEvent.KEYCODE_F1:{
                    Intent it = new Intent(Intent.ACTION_MAIN);                    
                    it.addCategory(Intent.CATEGORY_HOME);                   
                    it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);                    
                    mContext.startActivity(it);

          }
 

 

这样F3键就是打开相册;

    F4键就是打开照相机;

 F5键就是打开音乐;

   F7键就是打开设置;

  F11键就是打开计算器;

 F12键就是打开wifi;

F8键就是打开ES文件浏览器;

F2键就是打开APK安装器;

你可能感兴趣的:(android系统编译烧写)