原贴 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中成功的实现了放大和缩小