Is it possible to send data from an android Activity to adb ? I want to start an activity through ADB and pass it some data, perform an operation, then read the result. What is the best way to do this ?
For example: adb.exe shell am start -n com.example/com.example.Adder --ei operand1 10 --ei operand2 20 This adds 10 + 20 .. and stores the total 30. How do I fetch that value ?
These suggestions from my research are not an option: 1. write to a file then read it from adb using pull [the phone my not have an SD card, and there is a bug with android 4.3 that means run-as command doesnt work] 2. opening a socket and sending data through that [I dont want to depend on a network]
UPDATE: so I have been able to do something through adb forward as Chris suggested. I first start the adb forward: adb forward tcp:10000 tcp:10000;
Then on my android application.. I create a server socket and block at serverSocket.accept(); Then the client connects.. and then you can send data back and forth as you would with TCP/IP socket.
I just have one issue now, which is not documented in ADB; once the forward is setup, the client seems to connect to the server socket even if it is not setup yet on the android side. Why is that the case, is it possible to detect that the serverSocket is not setup yet.. once my clientSocket connects to this "shadow" socket ??
I have a code that alredy do that, please read my blog, is in spanish, but the code is a universal language :D
I use webSockets, a WebSocket server in Android device and a WebSocket client in a Web Page, via JavaScript.
Android device must be in USB debbuging mode, and you must execute 'adb forward tcp:38300 tcp:38300' in PC's command line to create the 'tunnel' that allow WebSocket connection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With