Any reason why I cannot take a screenshot of my app with ICS built

At first, this might not seem the proper place to ask this... But since I've only noticed this problem with my own app, I guess there's no other place to ask it. Maybe I'm doing something wrong, but I have no clue what...

As you are probably aware, ICS allows you to take a screenshot of the screen pressing Power + VolumeDown . I own an HTC One X and the shortcut is Power + Home . I don't know if this changes anything (maybe someone with a Galaxy Nexus could try it out).

My own app, Notification Agenda (I'm not going to link it so I'm not accused of SPAM or something similar but there's really no way I can post this question without self-advertising my app cause), doesn't allow me to take screenshots with the above key combination with my One X. I can take screenshots of any other app but it doesn't work on my own...

What the hell do you think I'm doing to "disable" this? My app is very simple and there's not much going on for this to happen. Any ideas?

Every time I try to take a screenshot of my app, I get this in logcat:

08-24 00:15:40.570: E/InputManager-JNI(277): An exception was thrown by callback 'interceptKeyBeforeDispatching'.
08-24 00:15:40.570: E/InputManager-JNI(277): java.lang.StringIndexOutOfBoundsException: length=83; regionStart=-1; regionLength=83
08-24 00:15:40.570: E/InputManager-JNI(277):    at java.lang.String.startEndAndLength(String.java:593)
08-24 00:15:40.570: E/InputManager-JNI(277):    at java.lang.String.substring(String.java:1474)
08-24 00:15:40.570: E/InputManager-JNI(277):    at com.android.internal.policy.impl.PhoneWindowManager.interceptKeyBeforeDispatching(PhoneWindowManager.java:2375)
08-24 00:15:40.570: E/InputManager-JNI(277):    at com.android.server.wm.InputMonitor.interceptKeyBeforeDispatching(InputMonitor.java:307)
08-24 00:15:40.570: E/InputManager-JNI(277):    at com.android.server.wm.InputManager$Callbacks.interceptKeyBeforeDispatching(InputManager.java:663)
08-24 00:15:40.570: E/InputManager-JNI(277):    at dalvik.system.NativeStart.run(Native Method)

That doesn't happen when the screenshot works. Instead a bunch of other calls to the screenshot app and many other things are logged.

Why is my app preventing the screenshot and generating the error above?


I would check if the app that takes the screenshot (the one that react to the key combination you talk about) is registered as system app. Android by design stops apps from sharing framebuffer, so any app trying to take screenshots won't do.

Dig deeper on that app's behavior and design.


One thing that can cause this is for FLAG_SECURE to be turned on for your window. http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_SECURE


I had the same problem. You can use the DDMS perspective of Eclipse to take screenshots, just run your app, enter DDMS perspective and click the camera icon on tab "devices"

链接地址: http://www.djcxy.com/p/62820.html

上一篇: 自定义HTML Shiv的缺点

下一篇: 为什么我无法使用ICS构建的应用程序屏幕截图进行截图