capturing another activity's screen in android
is it possible to have a service (A) which will launch an activity开发者_运维技巧 (B) and then periodically capture B's screen?
also, is it possible to send onTouch events from A to B?
basically, i'd like to make a bot which would use an application so i don't have to.
i guess it's not possible but had to ask.
You can't do that across Activity
s but you could create a view that held the Activity
that you want to automate. Then periodically you can grab the ViewDecorator
and do some processing on it and then inject touch events.
Screen captures of apps which are not the current app are prevented in Android devices due to security considerations. As far as I know up until Android 4.3 you can only do this in these scenarios:
- Your device is rooted
- Your app is signed with the same signature of the system (Google apps)
- With adb (debug environment): your device is connected via USB to a PC which is running adb shell commands, or either the USB is disconnected but you have started the native adb service in your device after each device reboot.
Some useful links:
How to programmatically take a screenshot in Android?
How to make a capture screen app on Android
http://code.google.com/p/android-screenshot-library/wiki/UserGuide
精彩评论