1

I am writing a small code to search for a number in whatsapp and send a text message.

I am able to send text message if I type in the script itself, but I wanted to paste the message from a file.

Is there any way to copy the content from a file instead os using the adb shell input text command.

My code below.

adb shell input keyevent 82

adb shell am force-stop com.whatsapp

adb shell am start -n com.whatsapp/.Main

adb shell input text "9800000000"

adb shell input keyevent 66

adb shell input text 'This%sis%sa%stest%smessage'

adb shell input keyevent 66

adb shell input text 'I%sam%schecking%slots%sof%sthings'

adb shell input keyevent 61

adb shell input keyevent 61

adb shell input keyevent 66

adb shell am force-stop com.whatsapp

Thanks,

Deepak

Vikasdeep Singh
  • 20,983
  • 15
  • 78
  • 104

2 Answers2

0

You don't say which scripting language you are using. You can do it from a Native binary (written in C/C++).

 1. Open the file for reading.
 2. LOOP
 3. Read a line into a string.
 4. convert all special characters to escape strings
 5. Use the command system to send the text:
     system("input "text Hello%sWorld");
 6. LOOP

I wrote such a binary called inputer. pasting into it works quite well, but each line is fork/exec'd so big files can get out of order, you need to test for each line completing or send as one huge call.

Jon Goodwin
  • 9,053
  • 5
  • 35
  • 54
-1

Yes, you actually can do this. It's kind of kludgy looking when you inspect the clipboard, but it works just fine.

First off, you can inspect the current clipboard contents with service call clipboard 1 from an adb shell (or, without shelling in first, adb shell service call clipboard 1). It may start out initially blank after a reboot, for example:

service call clipboard 1

Result: Parcel(
  0x00000000: 00000000 00000001 00000000 00000000 '................'
  0x00000010: 00000000 00000000                   '........        ')
#

You can put text into the clipboard using service call clipboard 2, which basically takes 3 parameters - two ints and the string you want to put on the clipboard:

# service call clipboard 2 i32 1 i32 0 s16 "Hi there"
Result: Parcel(00000000    '....')

To be honest, I'm not sure what the first two parameters are. One answer on Stack Overflow has suggested the first int is "number of items in the parcel" (one in this case) and that the second is the length of the string. However, I've used 0 for the second parameter and it works fine, and I can't find any documentation that matches up with this particular function...so take that for what it's worth.

In any case, it's basically creating a Parcel object with 3 fields, then passing it into the clipboard. The clipboard then unpacks the Parcel and sets the string value passed in as the clipboard's contents. You can see this when you go to retrieve the value afterwards:

# service call clipboard 1
Result: Parcel(
  0x00000000: 00000000 00000001 00000000 00000008 '................'
  0x00000010: 00690048 00740020 00650068 00650072 'H.i. .t.h.e.r.e.'
  0x00000020: 00000000 00000000                   '........        ')
#

Similarly, if you long-press on a text entry field and hit "Paste" after doing this, you will get the text that was set via the call service clipboard 2 line above (and it will look completely normal).

(The above examples come from my HTC EVO, running CyanogenMod 7)

Reference : https://android.stackexchange.com/questions/19710/is-it-possible-to-write-to-a-devices-clipboard-using-adb

Community
  • 1
  • 1
  • How can I send event long-press using code. Also in case if it highlights the paste button then how to select it again using code.. – deepak kukreja Jan 03 '15 at 15:28