android 向模拟发送多点触摸事件~

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值