In order for your application to be granted
android.permission.INJECT_EVENTS, your app has to be signed with the
system's platform key. See
http://stackoverflow.com/questions/5383401/android-inject-events-permission
On Wednesday, March 14, 2012 2:47:03 AM UTC-7, 献静 赵 wrote:
>
> Hi All,
> Can you guys help me solve the problem below?
>
> For ICS, it is easy to do the screen shot manually, by press the POWER
> and Volumn_Down key same time, and there is a instrument test under /
> icecreamsandwich/frameworks/base/packages/SystemUI/tests/ ,
>
> 101 /**
> 102 * Inject the key sequence to take a screenshot.
> 103 */
> 104 private void takeScreenshot() {
> 105 getInstrumentation().sendKeySync(new
> KeyEvent(KeyEvent.ACTION_DOWN,
> 106 KeyEvent.KEYCODE_POWER));
> 107 getInstrumentation().sendKeySync(new
> KeyEvent(KeyEvent.ACTION_DOWN,
> 108 KeyEvent.KEYCODE_VOLUME_DOWN));
> 109 try{
> 110 Thread.sleep(2000);
> 111 }catch(Exception e){
> 112 }
> 113 // the volume down key event will cause the 'volume
> adjustment' UI to appear in the
> 114 // foreground, and steal UI focus
> 115 // unfortunately this means the next key event will get
> directed to the
> 116 // 'volume adjustment' UI, instead of this test's activity
> 117 // for this reason this test must be signed with platform
> certificate, to grant this test
> 118 // permission to inject key events to another process
> 119 getInstrumentation().sendKeySync(new
> KeyEvent(KeyEvent.ACTION_UP,
> 120 KeyEvent.KEYCODE_VOLUME_DOWN));
> 121 getInstrumentation().sendKeySync(new
> KeyEvent(KeyEvent.ACTION_UP,
> 122 KeyEvent.KEYCODE_POWER));
> 123 }
> and in it's AndroidManifest.xml file, there is the user-permission
> flag:
> <uses-permission android:name="android.permission.INJECT_EVENTS" />
> I tried it, and it works, it can take the screenshot.
>
> Now I want to borrow this code a camera test case, it also use the
> instrument, I add the android.permission.INJECT_EVENTS in
> menifest.xml, (but this doesn't exist in Camera app's
> AndroidManifest.xml), andI run case, only see the volume adjustment'
> UI appear in the ui. Seems that the
> getInstrumentation().sendKeySync(new
> KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_POWER)), didn't run or
> take effect.
>
> Is it because the camera APP's AndroidMenifest.xml doesn't include the
> <uses-permission android:name="android.permission.INJECT_EVENTS" />?
>
>
>
>
>
>
> why,
>
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en