Like the headline suggestes I would like to make adb wait for an intent, is that possible?
I have an app that writes a file to filesystem and I would like to pull it with adb once its done, problem is I dont know how long it will take on each device.
Is there a way to make adb wait for an activity to close or wait for an intent?
Or maybe someone has a better idea of how to achieve what I want to do?
I have read through all of the pm and am API and there doesnt seem to be anything useful in there.
Thanks!
I don't think there is a way to wait intent by using adb.
How about using tmp file to check file writing completed?
from your app, create completed.trx file if target file writing completed
write simple scripts to check completed.trx file (routinely) by using adb shell command
if completed.trx exist, get written file by adb pull and delete completed.trx file by adb shell
Related
I have recently updated to Adb version 1.0.39.
After updating , when I use adb push command to push, after pushing it does not show the remote path file is actually pushed.
C:\Users\user\Desktop\__tmp>adb push file1.txt /sdcard/
file1.txt: 1 file pushed.
However, in earlier version 1.0.31, it used to show the path where it is exactly pushed. like pushed to /sdcard/ like this.
Is it possible to enable some kind of logging here ?
adb client never used to show the path where it is exactly pushed. It only used to print the location it asked the adbd to store the pushed file at. But it never had any means of actually knowing the actual location. So when simple guessing stopped working reliably in later Android versions they just removed the print out.
I have a file on the sdcard which is being written to by an app constantly, I need to pull the file from the device as it is being written to by the app, onto my windows host machine for further analysis.
adb pull is no good as it pulls the whole file then stops, but of course the file is still being written too. And anyway the file gets very big so i don't want to copy the whole file each time, just the parts that have been written to since i last read it.
adb shell dd might be an option but i can only get it to copy from one file on the sdcard to another file on the sdcard, i.e. not my windows machine:
e.g. adb shell dd if=/sdcard/input.pcm of=/sdcard/output.pcm then use skip and seek dd options.
if i used dd and a pipe:: adb shell dd if=/sdcard/input.pcm > output.pcm the output file has some corruption: 0x0D, 0x0D is added randomly to the pcm data. Same as if I just do adb shell cat input.pcm.
I also thought about writing the data to logcat and parsing it, but this is rather clunky and messy and there is a ton of data.
Another option might be splitting the file up in to lots of small files as they are being written and then using adb pull.
None of these are ideal. Ideally i'd like a program on the host that can pull the data at my control, e.g fopen, fread, etc. But I am not sure if this is possible.
Can anyone suggest how I might be able to fulfill my requirements:
Read all the file that's available to windows host
Read the parts of the file that have been updated since i last did a read (e.g every 100ms)
Many thanks in advance.
I think it is your specific requirement, so it doesn't matter to modify the source code of Android.
Why don't you implement another adb command? Then you can record the last read position and use adb newcommand filename to incrementally pull out the file.
The implementation of adb can be divided into two parts: host side, and adbd.
In host side, when you type a command, it goes to adb_commandline() in commandline.c.
if(!strcmp(argv[0], "pull")) {
if (argc == 2) {
return do_sync_pull(argv[1], ".");
} else if (argc == 3) {
return do_sync_pull(argv[1], argv[2]);
} else {
return usage();
}
}
Then the do_sync_pull continously communicate with the adbd. The adbd(adb.c) listens to the request sent from the host side.
A simple approach is to add another argument to the do_sync_pull, and let the adbd continously seek the file and send back the file content.
I have android device with root and i try to implement some small app. This app need to read files from /proc/pid/net . I made it with Runtime.getRuntime().exec(new String[] { "su", "-c", "cat /proc/"+PID+ "/net/tcp6" }); but I must accept su -permission for each pid. There are some other possibilities how i can to read system files in android from my app? Something with FileReader? How can I get the su-permissions without exec -commando?
The exec command IS how you get su permissions. You might be able to chmod 777 the files you want and then they can likely be read via java. That, or you could move the files you want to read to the sdcard, or your apps data location and read them from there. Here is something very useful for root. You won't have to manually use the exec command each time, but RootTools does still use exec.
I believe if you do something like:
Process p = Runtime.getRuntime().exec("su");
you will get the root access.
And then you can do just:
p.getRuntime().exec("command");
and then you won't have to put the su in as long as that process is still active.
Though, I haven't done what I explained above (with the process) in quite some time, so I may be wrong. You may still have to include su each time. But either way, I'd recommend using RootTools.
I already posted similar question, but still could not get my job done, so this a a second attempt, where
I would like to more clearly state my stumbling block.
So basically I am in Android phone's adb shell, communicating with the GPRS modem by sending AT commands.
I am able to do it by redirecting at command to the device file representing the modem; and I can read back
the response using cat utility running on the background (started earlier). I implemented it in a script
which can send a single AT command and read back the response. For example, here is the script to
send at+cops? to get the name of the operator the mobile is camping on:
#SendATCommand script
cat /dev/pts/7 &
echo -e at+cops?\\r > /dev/pts/7
The output looks as follows:
# ./sendATCommand
./sendATCommand
#
+COPS: 0,0,"AT&T",6
OK
/dev/pts/7: invalid length
Now here are two problems which I cannot resolve:
I still need to manually press ENTER button to get back adb shell prompt "#". Is there a way to return
to "#" prompt programmatically? Again, I am in adb shell.
The displayed response cannot be captured, neither in a variable, nor in file, (such as(#./sendATCommand > output.txt) Output.txt file will be empty. I tried various redirections, but still did not get it to work.
Can anyone please help me resolve those two problems (if ever possible)? Ultimately I want this little script to be
called from a "super" script (e.g. Perl or Powershell) running on PC to which my Android device is
connected, but there is no way to do it until those two problems resolved. Thanks a lot in advance!
I suggest that you try out my atinout program which should be exactly what you are asking for: a program to send AT commands from the command line and capture the output.
In your case the result should be like
$ echo 'at+cops?' | atinout - /dev/pts/7 -
+COPS: 0,0,"AT&T",6
OK
$
and to capture the output just put a file name instead of the last -.
I had similar problems with redirecting output to file. I resolved my problem by adding CMD /c in front of the echo command. I.e. if I understand correctly you need to tell the system that it needs to wait until command finishes executing and only then redirect output to a file. I was doing it in DOS.
Since you are running on ANDROID try adding sh -c in front of your command. Hope it helps.
I have created a batch file that fires adb shell command to start activity, send events to enter text into username and password text fields & click login buttons to navigate to other activity(screen).
how can i know that application navigate to other activity or want to know the response that tell me if login successful or not using shell commands.
Thanks,
Bhushan
Dollop, where I work, provides a record-and-play-back tool for Android that will do the things you suggest and save you the hassle of interacting with low-level shell commands. (It is currently limited to running on Windows in communication with Android devices). It's easy to configure and use, requires no programming, runs against real devices (which do NOT have to be rooted) and automatically saves screenshots as it plays tests. I'd love to hear your feedback.
try to get process (ps aux | grep xxxxx ) information to know the activity running or not