android 按键注入,模拟back,home,menu按键

第一,要有  <  uses-permission   android:name  =  "android.permission.INJECT_EVENTS" />      
第二,需要这个  android:sharedUserId  =  "android.uid.system"   系统app 
第三,cmd ="input keyevent 4" //back键注入
public  String doExec(String cmd) { 
             String s =  "/n"
              try  { 
                 Process p = Runtime. getRuntime().exec(cmd); 
                 BufferedReader in =  new  BufferedReader( 
                                      new  InputStreamReader(p.getInputStream())); 
                 String line =  null
                  while  ((line = in.readLine()) !=  null ) { 
                     s += line +  "/n" ;                
                 } 
             }  catch  (IOException e) { 
                  //  TODO  Auto-generated catch block 
                 e.printStackTrace(); 
             } 
             Log. d( "voice"  "s = "  + s);
              return  cmd;      
         }
第四,需要系统签名

猜你喜欢

转载自hanhaotian87.iteye.com/blog/1900559