I'm writing a flutter app and I want to make the phone appear as a mass storage device when connected via USB to a host computer. However, I want to control exactly what appears to be on the device.
In other words, if the application is running and the user connects the phone, the host computer would not see the entire Android filesystem but rather it would appear that the root of the filesystem is a specific directory that determined by the application.
I'm not looking for specific how-to but I want to verify that this is possible and get a sense of what would be involved. In general terms, how would I go about this?
I have business requirement where user wants to copy file from Android device into Windows 7 laptop via USB from android app(i.e. programmatically) because there is no wifi or cell data coverage available. I want to know if it is possible or not? How? Example would be appreciated.
Thanks
Look up adb, and from this you can do a simple script
The easiest way that I can think of would be storing the file in a specific location on the device's SD card (or internal memory), and then writing a program for the computer that copies the file from the device.
When I play Temple Run on Android, the app stores data somewhere. If I enable a USB connection and then try playing the game, the app now stores this information somewhere completely new, so that my previous information is not visible any more. Only when I disable the USB connection does the previous data get used.
In other words, I start off as a completely new user if the SD card is mounted and am only able to resume my old state when the SD card is unmounted.
What kind of storage is this? Why is it not visible when I mount the SD card? Can I keep data when switching phones and keeping the SD card?
Sounds Like it must be storing it on the SD Card, when you plug your phone into a USB port it mounts the SD Card to your computer not allowing access to it from your game... so the game will fallback onto internal storage (on phone).
When you plug your phone in it will be defaulting to mounting SD Card, Change this to "Just Charge" and try playing the game.
They probably check if an SD-card is available, and if not use the internal storage.
When you mount the SD-card, the applications cannot access it, so it switches to internal storage, where you do not have any saved games.
I am developing an application that has the following requirement:
When the device is connected to a computer via USB, the user should be
able to use Windows Explorer to drag files into and out of the
application directory.
The application will consume some of these files and produces others
which should be able to be copied back to the computer.
The target device does not have an external storage device (for
example an SD Card).
The directories that the files will be stored in should be accessible
whilst the application is running.
I've looked into the data storage page in the android documentation, but none of the methods stated there seem to do what I require.
Alternatively, is there a way to select the computer when the application is running and 'send' files via USB to the computer? How about for 'receiving' files?
What is the best way to fulfill this requirement?
When the device is connected to a computer via USB, the user should be able to use Windows Explorer to drag files into and out of the application directory.
If "the application directory" refers to a spot on external storage, this is possible.
The application will consume some of these files and produces others which should be able to be copied back to the computer.
If this is supposed to happen simultaneously, the device must be running Android 3.x or higher. Android 1.x and 2.x did not support simultaneous access to external storage.
The target device does not have an external storage device (for example an SD Card).
It needs to have something designated as "external storage". That does not have to be removable storage. On Android 3.x and 4.x, it is usually just a part of on-board flash that was designated to be accessible as external storage. In Android terms, "external storage" means "can be accessed by a host computer using USB and by all applications on the device as well".
The directories that the files will be stored in should be accessible whilst the application is running.
Again, this requires Android 3.x or higher. If this is a custom device, that most likely means you are going to need to use the recently-released Android 4.0 source code.
Alternatively, is there a way to select the computer when the application is running and 'send' files via USB to the computer? How about for 'receiving' files?
No and no, respectively.
What your going to want to do is use Environment.getExternalStorageDirectory. Even if there is no sd card, most android devices partition a part of the on board memory to be used as external storage.
When an Android device is plugged in to a PC (through USB?), is the internal file system mapped to a drive letter on the PC? So that one can copy files to and from the Android under Windows?
And, can Emulator simulate the situation when it's plugged in? How?
Thank you in advance!
Yes, it CAN be mapped to a drive letter. It was much easier with something like a Droid X (Android 2.3), since it would show up as a mass storage device (disconnecting the card from your phone in the meantime), but it's also possible on newer phones such as the LG G3 if you're willing to install 2 free programs, which you probably would like to have anyway.
ES File Explorer - Remote Manager (FTP Server)
First, you need a file manager, not only because the built-in one is useless, but also because you need an FTP server. Install "ES File Explorer" on your Android Device. Then in the options, turn on the "Remote Manager" option, which will activate the FTP server and show you its local address like "192.168.1.3:3721. You can now access your phone as an FTP site from your computer when on your local WiFi network.
Net Drive - Remote Drive Mapping Utility
Next, all you have to do is install NetDrive: http://netdrive.net/ It's freeware and seems to be used by a lot of companies, because it lets you map cloud storage to local drives. That will allow you to map your FTP server on your phone as a local drive.
Don't bother trying to map an FTP site with explorer. First, you may run into a problem that's apparently caused by Chrome, where you can't even add an FTP network location. You'll get an unexpected error telling you the path format is invalid. Interestingly, that is solved by opening the registry editor, then under [HKEY_CLASSES_ROOT\ftp] add a key named "ShellFolder" with string value "{E436EBB6-524F-11CE-9F53-0020AF0BA770}". The error will immediately cease occurring, with no restart or any other action required. Just go back in and add the ftp network location. That, however, still does not allow you to map it to a drive letter, which is why you need NetDrive.
As of Android 4, the wise ones have removed USB Mass Storage support for accessing the internal phone memory. So you no-longer get direct block-access (or a driver letter in windows). You can usually choose on the phone between MTP, or PTP (Media / Photo Transfer protocols) for whichever your OS supports better.
If your device has removable storage it should still support USBMS (with a drive letter) for that partition. At least Android still supports that, but your Manufacturer or Carrier-ware may still fail you here.
However, when it comes to the phone memory, there was a trade-off made in Honeycomb. Unified storage prevents wasted space (no more separate storage for phone / data, and having one fill up first and having confused frustrated users trying to move apps to SD, etc). The trade-off requires that:
Android can no longer ever yield up the storage for the host PC to
molest directly over USB.
Initially for Mac and Linux where support for MTP/PTP has been slower, You can use an FTP app on your phone. But now there is an increasing number of Desktop (PC/Mac/Linux) apps that understand and support the MTP or PTP protocols. You just don't get block access and so you can't get a drive letter without some hackery / third party software.
There have been hacks over the years to make FTP or WebDav or some other protocol work behind a windows drive letter, and something like could still work work for these MTP/PTP protocols, but I have yet to see any such consumer usable software for windows.
If your Linux distro doesn't include MTP support, gMTP seems pretty popular.
You can mount the device via USB but (in Win7 at least) it doesn't appear to have its own drive letter; rather it's treated like a camera or another media device. It doesn't mount automatically; you generally need to "opt-in" in the notification area with something like "Turn on USB storage"
Don't know about emulators.
Using Eclipse you can push and pull files to the emulator using the DDMS perspective. Doing similar on a real device, iirc will require root access to the device, at least to get to the 'sensitive' areas.
The SDK tools will also provide a way of push and pull via the command line.
possible with https://github.com/billziss-gh/sshfs-win
difficult finding good sshservers for android, know that at least one works but doesn't autostart at wifi and have to manually restarted, which it was possible to "come home from work, drive is connected"
this server seams to work fine
https://play.google.com/store/apps/details?id=net.xnano.android.sshserver.tv&hl=en_US
Wanted to backup(incremental) android device using Areca backup utility which requires src and dest to have drive paths.
After trying various methods like adb-sync, Syncthing, webDAV, etc. Got it working with ftp sharing.
Download any ftp server app. I used "WiFi FTP Server" by Medha Apps on Playstore to create a ftp server something like this- ftp://username:*#xxx.xxx.xxx.xxx:yyyy where username can be set in app settings and xxx is i.p. with yyyy as port number.
Map ftp URL to drive path by using free app- "DirectNet Drive"
Use the drive as if it's in your own system, though it will be slow being wireless.