- 积分
- 152
贡献17
飞刀2 FD
注册时间2011-8-3
在线时间59 小时

|
发表于 2012-4-5 21:08:18
|
显示全部楼层
参考一下,我是这样完成的,希望这个能帮到你!
private static Handler handler;
//在Activity的onCreate方法中对下列函数进行调用
private void createMessageHandleThread(){
//need start a thread to raise looper, otherwise it will be blocked
Thread t = new Thread() {
public void run() {
Log.i( TAG,"Creating handler ..." );
Looper.prepare();
handler = new Handler(){
public void handleMessage(Message msg) {
//process incoming messages here
}
};
Looper.loop();
Log.i( TAG, "Looper thread ends" );
}
};
t.start();
}
handler.post( new Runnable() {
public void run() {
Instrumentation inst=new Instrumentation();
inst.sendKeyDownUpSync(keyCode);
}
} );
Instrumentation inst=new Instrumentation();
inst.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(),MotionEvent.ACTION_DOWN, 240, 400, 0));
inst.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(),MotionEvent.ACTION_UP, 240, 400, 0)); |
|