Android sends a multi-touch event to a simulated system ~

Source: Internet
Author: User

I want to send a system multi-touch event to Android. I found someone asking online, but no one has the answer ~ No one answered after I posted the post ~ It took a long time to figure it out ~ Google's real TMD doesn't have a document. Let's look at an example ~

Paste the code ~ The following are suitable for 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: this function is 2.2. It is not in the SDK. You must have the android source code and compile it in the source code to link to it! This function is not displayed in the SDK.

Using this code, I successfully zoomed in and out in 2.2.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.