capturing another activity's screen in android - 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 Activitys 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

Related

Can I launch a specific app when android device get physically connected to a specific usb device?

Can I "register" a (already installed) specific app to be launched when android device get physically connected to a specific usb device ?
Eg.
I connect a keyboard (of a certain brand or with a special USBid/class) and it automatically launch a text editor app
I connect an USB soundcard and it launches an audio app.
And "better", is there an autolaunch on Android ? I plug a keyboard+storage device to my smartphone and Android will ask me if I want to install the apk from the storage (or download it from predefined url)
Obviously for security reasons I understand installing the app from the storage will need confirmation by user. But, once the app has been "registered" would it be possible to launch the app automatically without having a confirmation screen ?
I know I could get USB info with android.hardware.usb.usbdevice. My question is more about how I can tell Android to launch this app rather than another when usb device is connected.
I think you could register your app to receive a system broadcast like USB_ACCESSORY_ATTACHED and make the logic to launch your app when this happens.
Check https://developer.android.com/guide/components/broadcasts
https://developer.android.com/reference/android/hardware/usb/UsbManager.html#ACTION_USB_DEVICE_ATTACHED

Android - How to use the same USB device with two apps running simultaneously?

I am developing two apps that use the same USB device, but serve different purposes. The USB driver for both apps are the same, however, I would like it to where both apps can be running simultaneously while using the same USB device.
Unfortunately, as of right now, when using the USB device in App A, App B loses communication with the device when running in the background with App A active and receiving data. I would like both Apps A and B to receive the same data simultaneously with one app active while the other is running in the background.
I wonder, is this even possible?

Screen pinning as device owner not working

I'm trying to build a kiosk app using android 5's screen pinning feature. It seems that all I need to do in the app was to call startLockTask(), but this still allows the user to leave the app by pressing the recent and back buttons.
To pin the app in a way that does not allow the user to leave it requires the app to be a device owner. Based on sites such as this one, one needs to run
adb shell dpm set-device-owner my.package.name/.MyAdminReceiver
in order to set the device owner. However, that command failed with
java.lang.IllegalStateException: Trying to set device owner but device is already provisioned.
which, I heard, is caused by the file /data/system/device_owner.xml already being present on the device.
Since the device had just been freshly factory-reset, I suspect that it had come with an app already provisioned by the manufacturer, so I rooted the device. I would rather do it without rooting (since there will be some 70 devices I have to run the procedure on) but for research purposes, it can't be helped.
After rooting the device, I tried to find the device_owner.xml file but it wasn't there. I tried creating one anyway based on this answer, but the app still shows the pinning message and the recent+back buttons still unpinned the app.
So why can't I set the device owner? is there any way around it?
While it's true that I tried dpm provisioning on a newly reset device, #basilisk's comment hinted me at the answer. The device comes loaded with bloatware that provides default accounts. Disabling these apps finally allowed me to provision the device with dpm.

Starting and stopping an Android app remotely through PC or another smartphone

I have an Android Data collection App which collects sensors data. First, I enter the activity name in this app and then press the start button. After the recording is completed, I press the stop button and exit the app. For another activity, I restart the app again.
In my experiments, now I am using 5 smartphones on a participants's body while performing an activity so its bit difficult to start and stop this app for each activity manually as each activity is for 3-4 minutes and is a bit annoying.
I want to control this app remotely, either through another smartphone or PC. For example, like Airdroid:
http://airdroid.com/
However, Airdroid doesn't have the ability to start and stop (plus enter any data) at this point.
Is it possible to enter a name in this app, start it and stop it on multiple smartphones at the same time remotely ? May be using Bluetooth, local WIFI, or internet.
To summarize, I want to the following actions on an app remotely:
1) Start an App
2) Enter a name in its field (it can be worked around too so its optional)
3) Press start button
4) Press stop button when needed.
I looked it up online but most work has been done on controlling PC though smartphone and not the other way around.
Thanks
Zubkan
Integrate a HTTP server into your app, then you can control it easily using a web browser. A very nice option for Android is NanoHttpd, which comes as a java class.
Edit: Some additional notes:
This probably requires the phone to be connected via WiFi, because carriers might not allow this. And if the phone isn't rooted, you cannot run the server on Port 80, but Port 8000 or so will do.

Emulating touch event from input of external device for android device

Update(2013.08.15) : I managed to emulate touch event using 1. adb shell (slow), 2. Monkey tool(fast but not satisfying) and 3. monkeyrunner (best because I can couple it with python)
I'm trying to create an external device (probably using raspberry pi) which acts as input device for android. Specifically, I want the device to create touch event(touch, swipe... etc). The touch event should be created not only when certain app is activated, but also in background.
I have thought several methods of doing it.
Create an app(probably service) which receives data from the input device and emulate the touch event.(Probably monkeyrunner?)
Connect the android device to the external device and use adb to directly create touch event.
Make the device to mimic the behavior of joystick (I heard that this method only applies to several game apps. is it true?)
Which is the most viable method? Or is any of the method possible? (On rooted phone probably)
PS. For solution 1, I saw several apps (Remote desktop-like apps) which creates touch events using S/W. How does it work?(Using Android API, use adb or misc. methods... etc.)
Thank you for reading this question.

Categories

Resources