I want to convert the AT-command 'AT$WCDMA?\r' to a String[]. Then I want to send it to the modem with
invokeOemRilRequestStrings(java.lang.String[] strings, Message response)
I tried:
String[] wcdma = {"A","T","$","W","C","D","M","A","?","\r"};
or
String wcdma2[] = new String[1];
wcdma2[0] = "AT$WCDMA?\r";
but both are not working.
When I am using the linux bash it works fine with the following commands:
$ adb shell
# su
# stop ril-daemon
# echo -e 'AT$WCDMA?\r' > /dev/smd0
Has anybody an idea, what I am doing wrong?
Cheers
Felix
Related
I tend to read files name in a Android device beacuse I want to check the resource in this device is correct. Normally the order of manual testing is
adb -s 192.168.1.100:5555 root
adb -s 192.168.1.100:5555 shell
and when enter shell model, into the dir and ls
cd xxx\xxx\xxx
ls
Now I tend to write a python script to help me check it, so I try:
os.system('adb -s 192.168.1.100:5555 root')
obj = subprocess.Popen(["adb -s 192.168.1.100:5555 shell"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
and then I dont't know how to read file name and put file name into a list. Without shell model I try:
file_list = os.listdir("xxx\xxx\xxx")
l = []
for file_name in file_list:
l.append(file_name)
It works, but how can I do this in shell model? I mean switch path to adb shell path, then I can use this code to put file name into a list. Any idea? Thanks!
If you want to print all the files in a particular directory in a shell, you can simply try this:
for i in *; do echo $i;done
Here is what you can put in your python file.
import subprocess
p = subprocess.Popen('for i in *; do echo $i;done', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in p.stdout.readlines():
print line,
This will get your task done.
I am trying to get Android network stats using the code below:
string cmd = "cat /proc/net/xt_qtaguid/stats";
string info = Utils::exec(cmd);
It returns only headers of the information table, like:
idx iface acct_tag_hex uid_tag_int cnt_set rx_bytes rx_packets tx_bytes tx_packets rx_tcp_bytes rx_tcp_packets rx_udp_bytes rx_udp_packets rx_other_bytes rx_other_packets tx_tcp_bytes tx_tcp_packets tx_udp_bytes tx_udp_packets tx_other_bytes tx_other_packets
But when I execute this command via adb shell cat /proc/net/xt_qtaguid/stats, the result sames fine.
How can I deal with this issue? Do I need to root my phone?
EDIT
adb shell id's output:
uid=2000(shell) gid=2000(shell) groups=2000(shell),1004(input),1007(log),1011(adb),1015(sdcard_rw),1028(sdcard_r),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats) context=u:r:shell:s0
I made some buttons in my app that exec a bash cmd.
Here is my string:
final String[] test = {"su","-c","echo test > /system/test.txt"};
This cmd works, in fact, i can see the test.txt file on /system/ with the line test inside.
My question is: When i push on the button for exec that cmd the device create a toast with the string "echo test /system/text.txt".
I'm guessing this is due to "-c", anyway:
final String[] test = {"su","echo test > /system/test.txt"};
won't work, and:
final String[] test = {"su","-c","echo test > /system/test.txt >> /dev/null"};
won't work as well and create a toast showing "echo test /system/test.txt /dev/null"
is there any way i can avoid this "problem"?
Also, can anyone show me a little function that create a toast with a spinning wheel when i onClick to the button that exec it?
Thanks!!!
This extract from su manual should clear your question about -c option:
-c, --command=COMMAND
pass a single COMMAND to the shell with -c
And
final String[] test = {"su","-c","echo test > /system/test.txt >> /dev/null"};
won't work because Android don't have /dev/null device. To get it work you need to have a -c option after su and get a rid of /dev/null. You may use android API to delete this file instead.
I was trying to run Mobile originated call perl script on Emulator but getting error while running the script:
Below is the script:
Mo_call.pl
#!/usr/bin/perl -w
use strict;
use New_MO.pm;
for(my $i=0; $i<=4;$i++)
{
New_Mo::call_Originate();
}
New_MO.pm
package New_MO;
sub call_Originate
{
system("adb -s $device_id shell service call phone 763726728");
sleep 10;
system("adb -s $device_id shell input keyevent 4");
system("adb -s $device_id shell input keyevent 3");
}
1;
I am new for this things so if possible then please let me know where I am doing mistake.
Thanks
You should try using
use New_MO;
instead of
use New_MO.pm;
If this doesn't help, would you please share the error message you're getting?
Can you use ADB to type directly on an android device from a computer? If so, how?
Although this question is rather old, I'd like to add this answer:
You may use adb shell input keyevent KEYCODE resp. adb shell input text "mytext". A list of all keycodes can be found here
As Manuel said, you can use adb shell input text, but you need to replace spaces with %s, as well as handle quotes. Here's a simple bash script to make that very easy:
#!/bin/bash
text=$(printf '%s%%s' ${#}) # concatenate and replace spaces with %s
text=${text%%%s} # remove the trailing %s
text=${text//\'/\\\'} # escape single quotes
text=${text//\"/\\\"} # escape double quotes
# echo "[$text]" # debugging
adb shell input text "$text"
Save as, say, atext and make executable. Then you can invoke the script without quotes...
atext Hello world!
...unless you need to send quotes, in which case you do need to put them between the other type of quotes (this is a shell limitation):
atext "I'd" like it '"shaken, not stirred"'
To avoid expansion/evaluation of the text parameter (i.e. for special characters like '$' or ';'), you could wrap them into quotes like this:
adb shell "input text 'insert your text here'"
input does not support UTF-8 or other encodings, you will see something like this if you try it
$ adb shell input text ö
Killed
therefore if these are your intention you need something more robust.
The following script uses AndroidViewClient/culebra with CulebraTester2-public backend to avoid input limitations.
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
from com.dtmilano.android.viewclient import ViewClient
vc = ViewClient(*ViewClient.connectToDeviceOrExit(), useuiautomatorhelper=True)
oid = vc.uiAutomatorHelper.ui_device.find_object(clazz='android.widget.EditText').oid
vc.uiAutomatorHelper.ui_object2.set_text(oid, '你好世界 😄')
it finds an EditText and then enters some Chinese characters and a emoji.
You can achieve the same using bash and curl if entering text is the only you need.
#! /bin/bash
#
# simple-input-text
# - Finds an EditText
# - Enters text
#
# prerequisites:
# - adb finds and lists the device
# - ./culebratester2 start-server
# - jq installed (https://stedolan.github.io/jq/)
#
set -e
set +x
base_url=http://localhost:9987/v2/
do_curl() {
curl -sf -H "accept: application/json" -H "Content-Type: application/json" "$#"
}
oid=$(do_curl -X POST "${base_url}/uiDevice/findObject" \
-d "{'clazz': 'android.widget.EditText'}" | jq .oid)
do_curl -X POST "${base_url}/uiObject2/${oid}/setText" \
-d "{'text': '你好世界 😄'}"
Here is a Bash-based solution that works for arbitrary/complex strings (e.g. random passwords). The other solutions presented here all failed for me in that regard:
#!/usr/bin/env bash
read -r -p "Enter string: " string # prompt user to input string
string="${string// /%s}" # replace spaces in string with '%s'
printf -v string "%q" "${string}" # quote string in a way that allows it to be reused as shell input
adb shell input text "${string}" # input string on device via adb
The following code may be used for repeated/continuous input:
#!/usr/bin/env bash
echo
echo "Hit CTRL+D or CTRL+C to exit."
echo
while true; do
read -r -p "Enter string: " string || { echo "^D"; break; }
string="${string// /%s}"
printf -v string "%q" "${string}"
echo "Sending string via adb..."
adb shell input text "${string}"
done
You can see how it's done in talkmyphone.
They are using Jabber, but it might be useful for you.
When using zsh, here is a more robust function to feed text to Android:
function adbtext() {
while read -r line; do
adb shell input text ${(q)${line// /%s}}
done
}
While Zsh quoting may be slightly different from a regular POSIX shell, I didn't find anything it wouldn't work on. Dan's answer is missing for example > which also needs to be escaped.
I am using it with pass show ... | adbtext.