It's probably not possible due to safety issues and many other reasons, but it's worth a shot, so here goes:
Is it possible to push files from an Android device directly to a computer using ADB?
Why would you want that, you might ask. Good question. I find it useful to view larger Strings on a computer instead of on an Android device, especially since Log.d() won't show Strings of a length more of a couple hundred characters. Things like SOAP requests and responses, other xml files are not easily viewable on my Nexus 7. I've tried some things with the UsbManager class and the UsbDevice class, but I can't seem to find the USB-connection to my computer.
PS. I can think of other methods, like using a logging webservice, for all I care, or writing a script which pulls a certain (log) directory periodically, but I'm just curious whether or not it is possible, it makes my life ever so slightly easier.
As I can read in your question, you are quite aware of the fact that you can pull files from your Android device to your PC, so I won't suggest that.
To answer your question: No, this is not possible. It's not how adb works. Even if you could "push" from Android to PC, you need a piece of software to handle the data. Android does not contain any API which makes that possible, and neither does any part of the Android SDK.
Still you could use any of the methods you already know of (adb pull, Eclipse DDMS View, and yes, even a logging webservice, as you yourself suggested).
Hope this clarifies a bit.
You can push files from ADB to PC (eclipse).
In Eclipse Window-Open Perspective-DDMS
and then in DDMS view select your device from the left side list.
and in the Right side view, you will find a folder called mnt, inside it you will find sd card. There are your files. your devices files. Now to get them out to your pc
There are two buttons on the right side top.
one button says pull a file from device
another button says push a file to device
You need pull the file from device.
Select your respective file and click the pull a file from device button.
To copy a file or directory (and its sub-directories) from the emulator or device, use
adb pull <remote> <local>
For more details on the usage, refer this link
EDIT: What I understand is that you want your app to pull a particular file right? If yes, you need to use
public class YourAppCode {
public static void main(String[] args) throws Exception {
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(new String[] {"/usr/bin/adb", "devices");
}
}
Instead of devices, you need to send pull command along with the source and destination.
Related
is it possible to hide files in android by transfering/moving them to a location or sector (like in root folders or something) of which other apps don't have access to (via adb or termux or something)?.
I have mentioned adb and termux because i've seen performing actions like uninstalling system apps from device. and if possible, i don't want to root my device.
One humble request: i don't know the ABC's of app building/compiling, maximum i can do is execute commands in adb/termux. so if you paste any code, please also mention what to do with it.
i have tried:
putting dot at starting of the name of the files is too older method and everyone knows about it. encryption and decryption is too much time consuming process. And i don't have that much important data, i just want to hide it from direct access so that most of the people can't find it by normal methods.
Thank you very much
I need to read a string's value from my android application and write it into a txt file onto my PC, which will be read and used by an application running on my PC in parallel. The phone is connected to the PC using its USB cable, but if there's any other way.. I am open to suggestions.
The writing needs to be done recursively everytime the string changes and replace the existing string in the text file.
I have researched about adb and how I can use it for debugging and getting logs, but I do not know if it's possible to save only a variable's value.
Any method or suggestion is welcome, especially if it's simple and does the job.
Thank you.
Edit:
I'll add some details so you guys can understand my problem.
This is about my final year's project, I have to use voice command on a simulated robot in CoppeliaSim, a robot simulator.
I have developed the word recognition part using Google's Cloud Speech-to-Text API, it's running perfectly and at the end of the process I have a String containing the robot command, like "Move Up 50", "Rotate Left 20", which the simulator will be programmed to understand them as movement commands.
Now the problem is, how do I get the String into my PC and into the simulator? I have two options: CoppeliaSim provides me functions to read/write from serial port, but from all the research I have done, transmitting data from phone to PC is a big headache, plus I'd need some sort of USB to Serial port adapter.
Then I found a workaround, CoppeliaSim can read from text files that are present on my PC. If I could somehow use adb or any method to write the String into a file, I could do a repeating read from the file, thus transmitting the command to the simulator.
I ask you guys for help or any suggestions that can aid me into my problem.
For what code I have, it's just an example voice command app made by google that I modified, that after connecting to Google servers, doing some json packaging, returning a string and adding it to a list of strings that were previously identified, does nothing else.
I'm attaching the repository, if it helps: https://github.com/Hardstrike/Licenta
The weird function in MainActivity called Mutare is just for demo purposes, it moves a small car image on the screen by decoding the string. This is how the program will work in the simulator.
I hope someone can help me with any suggestions :) Thank you
I'd like to measure performance in a specific function (and everything it calls). To do so, it seems I should use Debug.startMethodTracing() and Debug.stopMethodTracing(), then somehow start DDMS tracing.
However, when I open a DDMS view in Eclipse and click the Start Method Profiling button, it starts immediately - not when startMethodTracing() executes. The result is a huge trace file with mostly irrelevant stuff in it. Too hard to narrow in (I tried a few times).
Apparently TraceView is deprecated. Should I hack a way to use that anyway? Is it any better? What is the correct approach to do what I need?
Thanks.
If you use Debug.startMethodTracing() and Debug.stopMethodTracing() a .trace file will be created on the device. The exact location of it is printed out in the logcat.
Look for entries that start with "TRACE STARTED" and "TRACE STOPPED". You then can use adb pull to get the .trace file from your device and open it in the tool of your choice for analysis (e.g. Eclipse or some third party product)
There is no need to manually use DDMS in Eclipse if you're using the above calls. The .trace file itself can simply be opened in Eclipse by using File -> Open
I've already asked this question before, but I never got an answer, so I'm trying again.
I'm trying to figure out how to mount a virtual drive into my android file system. By this I mean that I want to make a new folder (that doesn't really exist) appear somewhere in my Android file system tree and have all requests to view the contents of, read data from or write data to that folder (or any of it's supposed children), from all other apps, handled by my custom app.
I assume that to do this I will somehow have to override whatever part of Android handles requests to access files for reading and writing (e.g. FileInputStream and FileOutputStream), test whether the requested file is part of this virtual file tree, and if it is, handle the request, or else, pass it to the default handler.
The trouble is, I don't know what part of Android actually handles these calls. Can anybody help me?
I doubt you can go so deep in unrooted phone. It's kind-a possible with modified kernel: http://forum.xda-developers.com/showthread.php?t=1306336 . Unless you want to put changes into AOSP and compile it yourself, in which case I can't help you : ( .
Can I write a custom userspace file system that can be run on non-rooted factory devices through the standard available utilities?
I am aware of the existence of fuse-android, however as far as I have understood, it requires a rooted device. If that is not the case, please do correct me.
The goal I am trying to achieve is create a 'fake' FS that actually is mounted to a file.
I had the same need some time ago and came to the point where I had to admit that's not possible at all (mostly). It shouldn't be a problem to build libfuse for android, also the Java wrapper is no problem.
The real problem is that most of the systems I have seen aren't build with fuse support buildin nor do they provide modules which may be loaded (which would require root, but anyway).
You can easily find out if fuse is enabled by reading /proc/filesystems. It should list fuse, otherwise you will need root. But it's very likely that most android devices are build without fuse support.
My other ideas were to use another filesystem to "fake" something like fuse. This may be possible with nfs or some other network filesystem where you can implement the server by yourself. This whould enable you to write a fake fuse but I don't think it's worth it.
Edit:
And even if many devices would have fuse support buildin chances are high they wouldn't let you mount it as a user, you would need root access as your app wouldn't have the privileges to mount fuse filesystems.
Luminger almost has the right idea. Here's what I found on my Galaxy S3 (on Verizon):
The appropriate fuse stuff does exist in /proc/filesystems. So something must be using it, quite possibly system. However, when I attempt to execute 'fusermount', I get "Cannot execute -- Permission denied."
So it looks like all the FUSE stuff is there, but I've got no idea whether I could actually use it directly (dropbox? sshfs?) without rooting the device.
It depends on your implementation. What it sounds like to me is you want to have a physical file(s) that represent a full user space file system. Perhaps similar to a mounted .iso. If this is the case, I cannot think of any reason for needing root: You simply create/install the file somewhere such as /sdcard/ and "mount" your file system on top of it.
That said, if you want said file system to be accessible from other applications that you do not control, you'll need root as your application will be running in a Android sandbox otherwise.