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安装器;

更多相关文章

  1. Android(安卓)中使用自定义字体的方法
  2. Android(安卓)Studio 第五十三期 - 自定义EditText密码键盘
  3. android 算定义布局xml
  4. Android实现圆形头像-使用自定义控件
  5. Android(安卓)运行出错
  6. 【Android】Android(安卓)Clean Architecture推介
  7. 自定义全屏Dialog
  8. Android(安卓)Studio3.1.2 build.gradle classpath参数报错
  9. 1、ListView自定义控件下拉刷新(一)

随机推荐

  1. Android笔记:定时提醒、闹钟实现
  2. Android之Handler与多线程
  3. Android中8个常用的操作
  4. android 数据储存——ContentProvider(4)
  5. Android(安卓)自定义View——拖动选择时
  6. Android高效处理权限——EasyPermissions
  7. Android官方开发语音--Kotlin
  8. android sdk 编译--如何将源代码加入andr
  9. 使用https出错javax.net.ssl.SSLHandshak
  10. 解决在 Android(安卓)Recovery ADB Shell