I'm looking for a way to write a file from a Windows application to an Android device SD card over a USB connection. To do this, I will need to obtain the drive letter of the SD card, and it's mount point. My Windows application is written in C++, so I'm most hoping for a solution in C++. If not possible, perhaps there is a Java solution which can then be placed in a C++ wrapper to be called by my application's code.
I've searched around and come up with a few ideas but nothing seems to work yet. First, I came across Google's documentation on a method,Environment.getExternalStorageDirectory(), but my assumption is that since this is part of the Android SDK, it is only usable from an application residing on an Android device. Secondly, I came across some functions in Windows' native API (WinBase.h primarily), which provides a way of locating all drives and their corresponding letters, but even if I can get this information, I don't know how to determine which of these is the connected Android device's SD card.
Any help is appreciated!
I'm not a windows application expert but if you can use system calls in your C++ program to call adb.exe, then you can execute adb commands directly to the device.
For example if you can execute "adb.exe devices" you can get a list of all android devices currently attached to the computer. From there, you can use any adb commands to push files onto the device.
More information on the adb commands here: ADB wiki
What you're looking for is probably doing an adb devices in combination with adb push <your file> /sdcard/<file on sdcard>
Good luck!
Related
So as the titles suggests, I have a device whos bootloader is unlocked and adb has root access. Running android 7.0.
Custom recovery isnt an option as there is no TWRP for this android device so I am looking to both root the OS as well as flashing gapps and cant figure it out.
Does anyone have any suggestons on how I can install and update su and install gapps over adb shell?
Any help would be greatly appreciated.
You did not say what device you're using, but the following approach should be universal to all devices. Note that i do not take responsibility of what you do with your phone. Flashing wrong images can result in soft- or hard-bricks, so take care. But on the other hand, this method is rather popular and works for a lot of people, so i would suggest to try it out.
First of all, there were files which were called cf-auto-root files. With them you can easily root your phone.
Since the cf-auto-root provider has beeen superseded by firmware.mobi this method has become even easier. So if you visit https://desktop.firmware.mobi/, you can select your device, select the proper firmware and then configure a package which contains the firmware and the auto-root file. Now just donwload this file.
I could explain how you have to go on from this point, but the .zip archive contains literally everything you need. Just follow the steps inside the README.txt.
Once you got your phone rooted, there are several approaches to flash things like gapps without the need of a custom recovery. Just google for apps with such options, e.g. "Flashify" or "FlashFire". Just take the app which fits your needs best.
If you actually don't know where you can get flashable gapps archives, visit http://opengapps.org/.
Last tip: If you got your phone bricked, just try to flash your firmware agian via ODIN (without auto-root i would suggest), to restore everything to "default".
I've been trying to write a small program to copy a folder on my mac (10.10.3), containing a set of songs, into the music folder on my Galaxy S3 (GS3) when it is connected via USB. Clearly I could just use Android File Transfer (AFT), and copy the files in (manually), however this wouldn't teach me anything. My goal is thus to automate this act. Python seems like a good choice for this project, as it seems like mostly scripting (in fact a Bash script may suffice).
This should be simple, using a bash script like cp ~/../music_on_mac /.../music_target_on_android
However, the file structure of the GS3 doesn't show up in the finder (like you would expect from an ordinary USB drive). I can only see the file structure via Android File Transfer. From what I've read, this is expected behavior (I suppose due to formatting differences?). Thus I've been unable to find the target directory /.../music_target_on_android
My best guess (getting a bit out of my depth here), is that I need to copy the music folder, and then pipe it to AFT, and have AFT place it in/on top of the target Music folder on my GS3. Is this correct? If so, could anyone offer suggestions on implementing this? If not, alternative approaches or suggestions would also be appreciated.
I'd also note that I considered using ./adb push <local> <remote> to try to copy the files directly, however this pushed back that the device was read only. I'm also not familiar enough to find the proper directory on the GS3 (the one containing the target for the "Music" folder) using ./adb shell. There's also the added downside that in order to use a solution involving the ADT, one must have the ADT (which most people don't). Moreover, I want to keep it simple.
Research Update:
I've found that my phone will not show up in Finder because Google has disabled USB mass storage (aka mounting the phone as a disk) in favor of the Media Transfer Protocol (MTP). AFT is just an MTP client, needed because unlike Windows and Linux, OSX does not support MTP.
http://www.howtogeek.com/192732/android-usb-connections-explained-mtp-ptp-and-usb-mass-storage/
Based on tips, I've been able to implement an alternative based on creating an FTP server on my phone. Connecting to this gives me file system access and write privileges from my terminal, which is half the battle, however its quite slow. Thus I'd still like to find a way to automate instructions to Android File Transfer.
I am looking for a solution which uses Android API to transfer a text file from an Android powered device to a computer through USB cable. I have found USB host but I cannot use this because the computer can not act as a device for the Android host.
Do you have any suggestions how I can achieve this?
I have solved this problem by using adb status-window to continuously check for device status, and when a new device is connected, the required files are transferred to the computer using adb pull command.
In order to achieve a portable solution (i.e. to run independently of Android platform), I just copied the files 'adb.exe' and 'AdbWinApi.dll' into my application and used the adb from there.
Had similar problem where a software installed in PC needed to be able to access file inside the android phone through USB. After long research here is what worked for me (not sure if this is the best solution but it worked). Windows has Windows Portable Device(WPD) API which can be used to enumerate contents of a device through USB (and copy files between client and device).
There are few implementations in java
http://code.google.com/p/jmtp/ (works well but doesnt support copy function from device to pc though there is some support available to do this with source code)
another one is jusbpmp (available in google repository)
(if somebody finds a well documented and maintained implementation do share)
but since jmtp didnt work for me (copy function source compilation(for 64bit OS) failed), wrote C# program from scratch to copy files from device to PC. here is a nice tutorial
https://github.com/geersch/WPD/blob/master/src/part-3/README.md
You can write an app which will use http to contact your pc and send (POST) data to a known endpoint.
Keep in mind that the app will only have access to the data belonging to the app. You will not be able to access an arbitrary file from the file system
aafm is a small Python GUI utility that copies files between a computer and an Android device with MTP, using adb as the underneath layer. But as it is right now, the files get the timestamp of when they have been copied, instead of their original timestamp.
It would be great if we could set the last modified date in the device to match the last modified time in the computer.
I've been going through the list of adb shell commands in http://developer.android.com/tools/help/adb.html but so far I'm unable to find anything remotely similar to the classic unix touch command.
Does anything like that exist in this shell?
You can use busybox on android for that purpose. This is one binary acting as replacement (mainly with limited options) of small linux standard programs, e.g. touch. Read this and this
Now I found it is a part of android toolbox binary, but if you can't find it on a phone you can used own built touch binary and use it, source file is here. You just need to upload it on the phone, chmod and delete after using.
If you are talking about copying from host to the Android using ADB, it should use the original modify timestamp. The current code in adbd does a utime(). On some devices the utime() fails (see below). Copying from Android to host over ADB does not even attempt to set any timestamps. I do not know the reason for this omission. On my two devices (2.1 & 4.0) modify timestamp is set on write to Android but not on write to host. On 4.2 devices there is an issue with the FUSE filesystem and not allowing utime();
On devices without a real sdcard (that is, using FUSE) there will be problems doing utime() on a file unless you are root. This gets into the anomalous situation where you can create a file but not alter the timestamps. The only real solution is to make sure that ro.secure=0 or that you are running an insecure version of adbd.
We want to install our application on to (thousands of)phones and these phones will be later delivered to clients. Do we have to do this manually? Is there a faster way to do this?
For example, in Windows Mobile, if you put your installation files in a certain folder on SD card and when you insert that SD card to the phone the app is installed automatically to the device. Any similar mechanism on Android?
Thanks in advance.
You can create an update.zip file on an sdcard that will install an application, but you have to boot the phone into recovery mode to run it. I haven't used update.zip this way, but I saw it here: http://www.londatiga.net/it/how-to-create-android-update-zip-package/
Unfortunately it's much more complicated and slow than the old 2577\Autorun.exe method from WindowsMobile.
Other ideas...
ADB + USB hubs: Hook up a bunch of the phones at the same time using USB hubs, run a script to find the device ids with adb devices and execute adb install your_app.apk for each one.
(Requires taking the time to enable USB debugging on each device)
Install from the web: Host the .apk publicly or locally. Now you have to pull up the URL on the phone.
(Requires taking the time to checking that checkbox for installing from unknown sources on each device)
TinyUrl: host the .apk anywhere, shrink the URL, type it into the browser.
QR Code: If the devices happen to have a QR Code Reader like Google Goggles pre-installed, you could save yourself the typing of the URL.
SMS: If all of these phones have service and you have the numbers handy, you could broadcast an SMS to all of them.
Best of luck!
Basically, yeah. See this question for details. You essentially need an army of button-pressers.
I found this:
http://www.harmonyhollow.net/android_injector.shtml
So far it is the best solution I found. I guess it uses adb behind scenes.