android 向模拟发送多点触摸事件~
2013-06-24 16:36
323 查看
原贴 http://blog.csdn.net/ppcst/article/details/7255301
要向android发送系统多点触摸事件,发现网上有人问,但是没有人有答案~我也发过帖子没有人回答~搞了好久很搞出来~google真TMD不搞个文档,搞个例子~
贴下代码~下面是适合2.2的~
public boolean sendMoveDouble()
{
//point 1 release first
Log.i("key", "199199 send sendMovedoubl...........e");
Instrumentation inst = new Instrumentation();
MotionEvent e;
//nano
e=MotionEvent.obtainNano(SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(), System.nanoTime(),
0, 1, new int[]{0},
new float[]{bx1, by1, 1, 1}, 0,
0, 0, 0, 0);
Log.i("key", "199199 send sendMovedoubl...........1");
inst.sendPointerSync(e);
SystemClock.sleep(200);//Ms
e=MotionEvent.obtainNano(SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(), System.nanoTime(),
261, 2, new int[]{0, 1},
new float[]{bx1, by1, 1, 1, ex1, ey1, 1, 1}, 0,
0, 0, 0, 0);
Log.i("key", "199199 send sendMovedoubl...........2");
inst.sendPointerSync(e);
SystemClock.sleep(200);//Ms
e=MotionEvent.obtainNano(SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(), System.nanoTime(),
2, 2, new int[]{0, 1},
new float[]{bx2, by2, 1, 1, ex2, ey2, 1, 1}, 0,
0, 0, 0, 0);
Log.i("key", "199199 send sendMovedoubl...........3");
inst.sendPointerSync(e);
SystemClock.sleep(200);//Ms
e=MotionEvent.obtainNano(SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(), System.nanoTime(),
6, 2, new int[]{0, 1},
new float[]{bx2, by2, 1, 1, ex2, ey2, 1, 1}, 0,
0, 0, 0, 0);
inst.sendPointerSync(e);
SystemClock.sleep(200);//Ms
Log.i("key", "199199 send sendMovedoubl...........4");
e=MotionEvent.obtainNano(SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(), System.nanoTime(),
1, 1, new int[]{1},
new float[]{bx2, by2, 1, 1}, 0,
0, 0, 0, 0);
Log.i("key", "199199 send sendMovedoubl...........5");
inst.sendPointerSync(e);
return true;
}
MotionEvent.obtainNano这个函数是2.2的,在SDK中没有,你必须有android的源码,在源码中编译才能链接到!在sdk中提示没有这个函数
利用这个代码我在2.2中成功的实现了放大和缩小
要向android发送系统多点触摸事件,发现网上有人问,但是没有人有答案~我也发过帖子没有人回答~搞了好久很搞出来~google真TMD不搞个文档,搞个例子~
贴下代码~下面是适合2.2的~
public boolean sendMoveDouble()
{
//point 1 release first
Log.i("key", "199199 send sendMovedoubl...........e");
Instrumentation inst = new Instrumentation();
MotionEvent e;
//nano
e=MotionEvent.obtainNano(SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(), System.nanoTime(),
0, 1, new int[]{0},
new float[]{bx1, by1, 1, 1}, 0,
0, 0, 0, 0);
Log.i("key", "199199 send sendMovedoubl...........1");
inst.sendPointerSync(e);
SystemClock.sleep(200);//Ms
e=MotionEvent.obtainNano(SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(), System.nanoTime(),
261, 2, new int[]{0, 1},
new float[]{bx1, by1, 1, 1, ex1, ey1, 1, 1}, 0,
0, 0, 0, 0);
Log.i("key", "199199 send sendMovedoubl...........2");
inst.sendPointerSync(e);
SystemClock.sleep(200);//Ms
e=MotionEvent.obtainNano(SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(), System.nanoTime(),
2, 2, new int[]{0, 1},
new float[]{bx2, by2, 1, 1, ex2, ey2, 1, 1}, 0,
0, 0, 0, 0);
Log.i("key", "199199 send sendMovedoubl...........3");
inst.sendPointerSync(e);
SystemClock.sleep(200);//Ms
e=MotionEvent.obtainNano(SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(), System.nanoTime(),
6, 2, new int[]{0, 1},
new float[]{bx2, by2, 1, 1, ex2, ey2, 1, 1}, 0,
0, 0, 0, 0);
inst.sendPointerSync(e);
SystemClock.sleep(200);//Ms
Log.i("key", "199199 send sendMovedoubl...........4");
e=MotionEvent.obtainNano(SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(), System.nanoTime(),
1, 1, new int[]{1},
new float[]{bx2, by2, 1, 1}, 0,
0, 0, 0, 0);
Log.i("key", "199199 send sendMovedoubl...........5");
inst.sendPointerSync(e);
return true;
}
MotionEvent.obtainNano这个函数是2.2的,在SDK中没有,你必须有android的源码,在源码中编译才能链接到!在sdk中提示没有这个函数
利用这个代码我在2.2中成功的实现了放大和缩小
相关文章推荐
- android 模拟发送多点触摸事件
- android 模拟键盘事件/android发送虚拟按键
- 【Android】技术调研:用代码模拟屏幕点击、触摸事件
- android adb shell 模拟广播发送和键值事件
- Android 使用代码主动去调用控件的点击事件(模拟人手去触摸控件)
- 【Android】技术调研:用代码模拟屏幕点击、触摸事件
- Android 向系统发送多点触摸事件总结
- android monitor tool (8.0 模拟发送按键及触摸屏事件实现)
- Android中performClick方法---代码调用点击事件(模拟去触摸控件)
- Android发送dtmf键盘事件(模拟通话界面键盘事件)
- Android:处理触摸事件
- 一步一步学android之事件篇——触摸事件
- Android通过代码模拟物理、屏幕点击事件
- Android自动化测试初探(四): 模拟键盘鼠标事件(Socket+Instrumentation实现)
- android 的触摸事件的分发拦截机制分析
- 对于android触摸事件模型的一些理解
- 真机模拟触摸事件
- Android第一次触摸屏幕没有产生事件
- Android ---模拟手机发送短信
- Android: 详解触摸事件如何传递