Controling Android with Arduino (Dpad Input, Home Button, Recent Tasks, Media Buttons...) - android

I started to investigate how to send via Wifi some commands to control an android device (Nexus 7 - rooted). So I created an UDP Server app in Android that simulates some buttons through KeyEvent class (for the moment I'm trying to send UDP messages from PC via Wifi to test).
The problem is that it only works within the app, if I open Google Music and I simulate increase volume the app close due to INJECT_EVENTS Permissions.
So at this point I need some ideas to proceed with this project and these are my different options:
Continue with Wifi communication and try to create a service able to skip system permission to simulate all Android buttons I want.
Try BT communication - maybe there is a way to communicate directly to the OS instead through an app.
Try USB communication - I know that through adb shell commands you can simulate all the buttons but...Is it possible to send adb commands from an arduino? Should it be only through USB or could it be via Wifi?
I'm avoiding Tasker/Autoshare solution as it's very slow for what I need.

Related

Android connect/disconnect a specific Bluetooth device (or BT profile) from command line

There are already several topics for enabling/disabling Bluetooth via command line on an Android device. But these don't help me for my particular case, where the Android device is a Chromecast 4K with Bluetooth. That is, if I entirely disable Bluetooth on Chromecast – usually to disconnect the BT headset –, the Bluetooth remote will get disconnected as well!
So, what I need is a shell command sequence (usable for Button Mapper) which either
disconnects/reconnects just a particular Bluetooth device (preferable by friendly name, but BT Address is also OK) or
disable/enable just a certain profile (A2DP in our case), in order to leave remote control functionality untouched.
Obviously I'd avoid rooting, but as a desperate solution I can root my Chromecast device, if there is no other way.

Bluetooth SPP server using Flutter

I want to communicate with a Sepura STP8000 radio from a Flutter app via Bluetooth (specifically SPP, Serial Port Protocol).
I first tried the flutter_bluetooth_serial and was able to connect and communicate successfully with another Android device running a Bluetooth Terminal app, sending text back and forth. But when I tried connecting to the Sepura radio I was out of luck. With my basic understanding of Bluetooth, I'm under the impression that the Sepura can only act as a client, so I would need my Flutter app to start a server and listen for an incoming connection (but I might be wrong).
So instead I tried the bluetoothadapter plugin, which seems to be able to act as a server (at least it has a startServer() method). That didn't work either. I was unable to connect from the Sepura, and also unable to connect from another Android device, so I'm not sure if startServer() actually starts a SPP server or not.
Any ideas for how I can listen for incoming Bluetooth SPP connections in my Flutter app? It's fine if it only works on either Android or iOS, as long as it works on one of them.

Fake Incoming Call on an Android device

Is there a way to fake calls for android devices that I have plugged in via usb? Some way to trigger a call using ADB? If so, how do I do it?
I feel like this might be a duplicate question but I can't find a SO question for it. This is the closest question, but it only relates to the emulator.
Here's some things I've tried. I would like to do the reverse of the following command:
adb shell am start -a android.intent.action.CALL tel:1112223333
Just like the other guy said in the question I linked to above. Except I would like to do this on a device, instead of in the emulator. For the work that I am doing the emulator is not sufficient for testing phone calls, I can only run my tests on actual devices. Our "solution" doesn't have emulator support.
So normally I would telnet into the local host using the emulator's port but I can't do that, so can I telnet into a plugged in device? Is there a way for me to fake an incoming call on a plugged in device?
To explain why I would want to do this, I am making modifications to AOSP at this time. At the moment we have not modified the emulator to work with our changes, but we are making modifications to telephony. Eventually getting the emulator to work will be important but at this time it would be ideal if we could test telephony with fake calls using the devices we have access to.
It is entirely possible that this is not even possible but if someone has experience with this I would love to know. I feel like there should be some tests somewhere for faking phone calls on devices before they release a device to the public.
Telnet to your Android device
Alternatively to adb you can also use telnet to connect to the device. This allows you to simulate certain things, e.g. incoming call, change the network connectivity, set your current geocodes, etc. Use "telnet localhost 5554" to connect to your simulated device. To exit the console session, use the quit or exit command.
For example
# connects to device
telnet localhost 5554
# set the power level
power status full
power status charging
# make a call to the device
gsm call 012041293123
# send a sms to the device
sms send 12345 Will be home soon
# set the geo location
geo fix 48 51

Android - USB Open Accessory Mode Bug

I currently have a Nexus One that I have communicating with Linux using the Android USB Open Accessory library. I have built a Linux application that I am able to send commands to an Android client application to perform tasks.
The problem I have is whenever the activity changes on the Nexus device I lose connection to the device. For example, if I send a dial command to Android from Linux the phone will call the Android dialer and make the call. After coming back from the call though, my Android application acts as if the USB cable is disconnected and I am no longer able to send it commands from Linux. I experience the same issue if, while in the Android application, I press the home button and then relaunch the client application.
Any ideas?
On the Nexus device have the Open Accessory connection run in a service.
That way the connection won't be killed when the activity is destroyed.

Sending commands from a PC to an Android phone - via physical connection (USB, Serial, etc)

I'm working on a project to automate some tasks (such as play a song, play a video, receive bluetooth data, etc) on an Android phone from a PC.
Basically the PC will send a notifier to the phone and an app or something on the phone would then process the notifier and do 'something'. The opposite of this really:
http://code.google.com/p/android-notifier/
I've seen some examples showing how to send commands to an Android listener app or service via a network connection, but in this case, I would much rather the transmission be over a physical connection.
USB
Ideally, I'd like the connection to be via the USB port. But I've seen some posts online that suggest that the SDK does not natively support this. (Android apps, communicating with a device plugged in the USB port).
Is there some other SDK/API out there that makes this easier?
I've seen some posts on the ADB, but don't really get it... Would that work?
(http://developer.android.com/guide/developing/tools/adb.html)
Serial over USB
I've also seen some sites that show how to use a breakoutbox to perform bi-directional serial communication, but only with the G1. Is this possible with newer phones?
The Phone
I'm open to really any newish phone. I'm currently looking at the Galaxy S, because it has the video out through the headphone jack. I'm open to rooting if need be.
Implement a HTTP server in your app, then put your phone in USB Tether mode. This will create a local network between your phone and your PC. You should then be able to send HTTP request or create websockets using the phone's ip.
EDIT : I tested it, and it works, see here
What you can do is the phone acting as a server and then use adb to forward ports [1].
In this scenario the pc app would connect to localhost which would be redirected to the app on the phone via the usb cable.
But if you go this way, you might just as well simply connect directly to the phone's ip (without the adb port forwarding)...
[1] http://developer.android.com/guide/developing/tools/adb.html#forwardports

Categories

Resources