Simulate physical buttons; get the name of the currently displayed Activity

Source: Internet
Author: User
//////// Simulate the key-press method private void sendkeycode (final int keycode) {New thread () {public void run () {try {instrumentation inst = new instrumentation (); Inst. sendkeydownupsync (keycode); // The following method can be used before 4.0 or 3.0: // keyevent K = new keyevent (keyevent. action_down, keycode); // (iwindowmanager. stub. asinterface (servicemanager. getservice ("window "))). injectkeyevent (K, true);} catch (exception e) {e. printstacktrace ();}}}. start ();} // call, for example, simulate the return key sendkeycode (keyevent. keycode_back); ------------------------------------------------------ // obtain the name of the currently displayed activity private string getact () {activitymanager manager = (activitymanager) mcontext. getsystemservice (context. activity_service); string activityname = manager. getrunningtasks (1 ). get (0 ). topactivity. getclassname (); Return activityname ;}


 

Simulate physical buttons; get the name of the currently displayed Activity

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.