I'm trying to get my computer (Mac/Linux) to send touch commands to my Nexus 7 tablet via ADB. I've found that I can successfully send touch events via "adb shell input tap x y", but the noticable delay is inhibiting what I can do. I would need to be able to send several per second, but this method sends at about 1 per second. I'm hoping to in the end control the inputs via a python script on the host pc if that's possible.
Thanks!
Have you taken a look at monkeyrunner?
Or if you are looking for an automation test framework, you could try robotium.
Related
I'm looking to use five android phones to take a photo simultaneously (from different angles).
I'd like to control the phones via a pc (linux or mac) and ideally they're all connected via USB/Ethernet.
I'm an EE, but I don't have much Android experience, so looking to get some feedback based on what I've read so far.
Looks like the Scrcpy library could work here, controlling the 5 devices via adb. I see it allows for multiple connections, have anyone tried this?
I could potentially create a PCB that integrates with the headphone jack of each device and control via push button and 470ohm resistor?
I could potentially build a client app on the Android devices, which connects to a server app on linux/mac (basic TCP/IP client server)
What routes/design would people take on architect-ing such a system?
Thanks for your help and reading this.
What do you mean by "simultaneous"? How much leeway do you have- seconds? Milliseconds? Somewhere in between? Because those can require different techniques.
The easiest thing is to use adb on all 5 devices (I think you can, but I've never personally done more than 2 at once). YOu can even use adb over wifi, so you don't need the cables. You can open the photo app on each (either manually or via adb) then send an input command down via db to each device to send a click of a CAMERA media button, which should cause them to take a photo (of course this is dependent on the camera app honoring this keycode).
The problem with that approach is that you're going to have to have a script that either sends commands to each device 1 at a time (they'll be off by seconds) or spawns N processes that each send a command. That obviously isn't going to be simultaneous either, although it would be closer.
If you really do need simultaneous, its better to write an app on the PC that sends a UDP multicast message. Write an Android app that listens for it. Then when the device receives the message, take the picture. This will assure each device gets the message at the same time, and the picture should be within milliseconds of each other. Of course, if you don't need ms resolution this is total overkill.
I am developing android app for OBD.
I have written bluetooth connection with OBD device code in thread.
This thread is working for some devices but the device whose processer is very good then it has problem.
Let me know how I can manage for those devices?
Thank you in advance.
So if I get you right, your code gets executed too fast? If you send 1 command and then nothing, it works right?
Only problem I could imagine, is that you are sending your commands too quickly. You will have to make a smart way of sending commands to the OBD-device, or just let the thread sleep after sending a command. The base problem is that your device can send multiple commands, while the obd-ii device didn't handle it first command and then it reads in multiple commands at a time, which makes it confusing for him.
Update:
When you send a command, the OBD protocols sends the command and a ECU reponds on the command, and the answer gets responded to you. During that time, the OBD-II device does not follow any other instructions. After the respsonse, it looks into the buffer and processes that command. Look at it as a single thread that can only hanlde 1 command at a time.
Standard, the time the OBD-ii device waits, is 200 ms. Then it sends a response back to you. You can alter this by setting the timeout lower. (Look into AT-commands for ELM-327), or by adding a 1 after your command, so the OBD-II device knows it should respond back when he found 1 possible answer.
I know, I can listen input devices from /dev/input/eventx on Android/Linux. If you are superuser, you can also send events to the device through that.
I would like to send mouse events to my Android device as superuser. However, in order to do this, a mouse must be connected to the device via USB or bluetooth connection. Without it, I get error as Could not open /dev/input/event8, No such device when execute this command on adb sendevent /dev/input/event8 xxxx xxxx xxxxxxxx. In this case, the node was attempted to be created using the mknod /dev/input/event8 c 13 71 command.
The problem is solved when I connect a bluetooth or USB mouse to the device. The device is created automatically under /sys/devices/platform/tegra_uart.2/tty/ttyHS2/hci0 named hci0:11 also create input event /dev/input/event7 (major 13 minor 71). After that I can send events to that node and control Android mouse cursor. But I want to do this without connecting a mouse to the device.
Could anyone suggest how can I create a mouse input device (like when a mouse is connected) on my android device virtually?
From what i see you should create your own virtual device with your own driver , Fortunately there is an easy way to do so using uinput
There is an easy guide for getting started here , and this question can be a good guide to write your own virtual driver.
I thought this can only be done if you have access to kernel , and create your own ( i dont think modifying user rom is a good solution ) , but after reading this , it is clear that Uinput can run in user mode.
Note :
I agree with recommendition to use touch events ; as this solution is more common and makes sense , check second suggestion is this answer
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.
Is there any command to perform sensor event in device using monkey or adb like using monkey we can perform so many commands for touch long press etc.but i am not getting any sensor commands
Does anyone have idea about this please share.
Thanks in advance
You can inject events using adb shell sendevent command. Name of the device to send the events to is going to be device specific (actually it could change with software upgrade on the same hardware). You can get a list of the devices with getevent -il
Another option would be to use some low-level development tool to send I2C messages (most sensors sit on I2C bus).
The problem is that while you can inject the extra events - it would not stop the actual sensor from sending its own. So your fake sensor reading would only last till the next real update.