首页 > 代码库 > 模拟物理按键;获取当前显示的Activity名

模拟物理按键;获取当前显示的Activity名

//////////模拟按键方法   private void sendKeyCode(final int keyCode){        new Thread(){            public void run(){                try {                    Instrumentation inst = new Instrumentation();                    inst.sendKeyDownUpSync(keyCode);/////////以下方法在4.0或是3.0之前可以用//                  KeyEvent k = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);//                  (IWindowManager.Stub.asInterface(ServiceManager.getService("window"))).injectKeyEvent(k, true);                }catch(Exception e){                  e.printStackTrace();                }            }        }.start();    }//////////调用如,模拟返回键 sendKeyCode(KeyEvent.KEYCODE_BACK);--------------------------------------------------------////获取当前显示的Activity的名字private String getAct(){   ActivityManager manager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);      String activityName = manager.getRunningTasks(1).get(0).topActivity.getClassName();        return activityName;  }


 

模拟物理按键;获取当前显示的Activity名