//////// 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