james
james

Reputation: 354

How to use adb socket to get the result from the phone?

I have written an executable file, and push it into /system/bin.

After run the file, it will give a result in float.

Now on PC side, I want to get this result.

At first I write this float number into a file and use 'adb pull' to pull this file, then read file. Because I need to do this operation frequently, may 2 times per sec. This cause bad performance of the phone.

Wheather it will be little influence when I use adb socket? Where my executable file should output? How adb socket get the result?

Thanks. James.

Upvotes: 1

Views: 3715

Answers (3)

Jason Lee
Jason Lee

Reputation: 11

I had the same question before, you don't need output result to file, just output your result to a socket port, and use adb forward to get the result on your pc by adb socket. this is what you need solution.

adb forward tcp:18000 tcp:19000

this command means,pc's tcp port 18000 bind to device's tcp port 19000, if you send data to 18000 port on pc, you can get data from 19000 on device.vice versa.

Upvotes: 1

brianestey
brianestey

Reputation: 8302

You could potentially use logcat as a medium for getting data from your Android app to your desktop machine provided there is an ADB connection available.

My thinking is that there are two pieces:

  1. Log your app output with logcat to a unique TAG on the Android side. For example,

    Log.d("MyAppOutput", "This is the output I am looking for");
    
  2. On the desktop side, you could run a command line that looks specifically for that TAG, something like:

    adb logcat -s MyAppOutput
    

I believe this would allow you to read the results from the Android app in near realtime. If you need to know the timestamp of the log message, you could add the -v time parameter to prefix each message with a timestamp.

Upvotes: 1

bchurchill
bchurchill

Reputation: 1420

If you're leaving the phone connected, you could probably just do

adb shell /system/bin/myexecutable

and just have your binary print its output to stdout. As long as your program runs quickly, twice per second shouldn't be too fast. Otherwise, you could do

adb shell cat /somewhere/myoutfile

to see what's in a file currently.

Upvotes: 1

Related Questions