Mount MTP device on windows - android

I am attempting to mount an android device on a machine running Windows 10 for the purpose of accessing files via a Java application. I am aware that the consensus is one should use a WebDav or FTP server, but I would like to avoid this if possible. I have spent many weeks researching this and have finally decided to reach out to the brilliant minds of stack overflow.
To mount the MTP device we need a file system library similar to fuse for Unix. For windows the two obvious choices are:
dokany
winfsp
As far as I understand there are two main APIs/libraries to access MTP devices:
libmtp
WPD
I have managed to compile libmtp for windows using msys2/Mingw64.
The way I see it I should use an application like mtpmount or try to port a linux application like simple-mtpfs using a file-system library like dokany instead of fuse.
However, when I try to use mtp-mount (which uses the WPD API) it doesn't list any devices, and when I test libMTP using the provided examples I get errors like this:
libusb_open() failed!: No error
libmtp version: 1.1.18
Listing raw device(s)
Device 0 (VID=04e8 and PID=6860) is a Samsung Galaxy models (MTP).
Found 1 device(s):
Samsung: Galaxy models (MTP) (04e8:6860) # bus 1, dev 10
Attempting to connect device(s)
OK.
LIBMTP PANIC: Unable to initialize device
Unable to open raw device 0
I don't know how to proceed. Any help would be greatly appreciated.
Update
I got libmtp working using libusbk-dev-kit. Specifically, I used the libusbK-inf-wizard, to create drivers for my device. I tested the libusbk driver and the WinUSB driver and found they both solve my problem.
Also, I build mtpmount from sources and found it to work as well.

I found your question while looking for something very similar: how to talk with MTP (a Garmin Alpha 200i handheld GPS unit - not a phone) using Python 3 on Windows 10.
Glad to see you found a solution! I found a partial solution for my issue using your leads (Specifically, mtpmount), and am wondering if it provides another alternate solution for your issue.
I'm also wondering if you've discovered any more about mtpmount since you found your solution.
Based on your lead, I went to the mtpmount link. I was able to get a full solution for the windows command line by 1) downloading and running the latest .msi for dokany, making sure to select all the components for installation, then 2) downloading the latest .exe (it's not an installer - it's the actual mtpmount executable) for mtpmount. That's about as smooth of an installation process as one could hope for in this realm! Hats off to the developers on both of those projects!
The only differences vs the mtpmount docs I found were that 1) the executable name in the docs didn't exactly match the executable name from the downloads - certainly not a big deal, and 2) the pound sign has to be in double quotes - at least that was the case in powershell, and 3) a good thing: you can specify the drive letter in the same ID# syntax:
PS C:\Users\caver\Downloads> .\mtpmount-x64.exe list available
This is mtpmount, version 19.8.0 from commit 43033d6
This program comes with NO WARRANTY. Usage only at your own risk.
Available Connections and Storage Media:
Connection Elements: Contains 1 storages that can be mounted
|-- Storage E: [ID #0]
Connection My Passport: Contains 1 storages that can be mounted
|-- Storage F: [ID #1]
Connection Alpha 200i: Contains 2 storages that can be mounted
|-- Storage Internal Storage [ID #3]
|-- Storage Memory Card [ID #4]
Use mount command to make one of them a windows removable drive
PS C:\Users\caver\Downloads> .\mtpmount-x64.exe mount "#3" h:
This is mtpmount, version 19.8.0 from commit 43033d6
This program comes with NO WARRANTY. Usage only at your own risk.
Drive H:\ is now Alpha 200i\Internal Storage. Don't forget to unmount the drive (using unmount command) before disconnecting your device
PS C:\Users\caver\Downloads>
Then you do your drive access work. Then you run this to dismount:
PS C:\Users\caver\Downloads> .\mtpmount-x64.exe unmount "#3"
This is mtpmount, version 19.8.0 from commit 43033d6
This program comes with NO WARRANTY. Usage only at your own risk.
Alpha 200i\Internal Storage has been unmounted successfully.
Syncing Alpha 200i. DO NOT UNPLUG THIS DEVICE YET!
the terminal pauses for about 5 seconds here
Cache OK
All content synced to Alpha 200i. You may now unplug this device.
PS C:\Users\caver\Downloads>
My questions about this:
does dokany affect the rest of your file system access, by running all file system operations through its proxy for all drives? If so, does that slow things down or add another possible route for file system corruption in the event of an undiscovered bug in dokany or such?
we work with the Garmin GPS units in an environment where unplug timing can't really be reliably controlled. In other words, we really need to be able to unplug immediately after the transfer is done, without waiting for the pregnant pause during the unmount process. What's the word on hot-unplugging of a MTP device that's mounted using mtpmount? Unplugging without running 'mtpmount unmount', and also, unplugging during the pregnant pause? Of those two options, seems like it would be safer to just not run unmount - you get the impression that the 5-second sync would be a really bad time to unplug... For USB Mass Storage Devices, I know it's always recommended to properly eject the device from Windows first, before physically unplugging, but we've never experienced a problem due to hot-unplugging of USB Mass Storage Mode Garmin GPSes.
have you made this all into a turnkey installer solution, i.e. one overall installer that installs dokany then installs mtpmount then also installs the rest of your application? I am not familiar with installers like Nullsoft or such and I definitely plan to RTFM there, but just wondering if you've encountered any specific hiccups on these lines.
Thanks and congrats on getting it working!

Related

Getting "error: device offline" from adb.exe in Android Player SDK / Setting Up Unity Remote 5 (Solved)

First of all, this is my first post here and I'm a beginner so my apologies if this ends up being a stupid question or my format is wrong, but any help is appreciated.
Essentially my problem is in trying to set up Unity Remote 5 for debugging in Unity. However, I believe I've finally narrowed it down. The error I'm getting now seems clear:
CommandInvokationFailure: Unity Remote requirements check failed
C:/Program Files/Unity/Hub/Editors/2019.4.17f1/Editor/Data/PlaybackEngines/AndroidPlayer\SDK\platform-tools\adb.exe forward tcp:7201 tcp:7201
stderr[ error: device offline]
stdout[]
exit code: 1
I've looked into this error and came upon this: https://stackoverflow.com/a/39031464/14948855 which seems like it might be useful to me, however the issue is I don't know how to run the commands he suggested and stack overflow made it clear it didn't want me posting a question as a response to that question and I don't have enough prestige to comment.
I'm trying to run "sudo adb kill-server" from an ubuntu linux terminal on windows from the directory abd is in (C:\Program Files\Unity\Hub\Editors\2019.4.17f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platform-tools), but it won't run.
proof command not found
I've tried adding it to the path on my computer: I added the directory listed above to "Path" in my "Environment Variables".
My phone is plugged in, I've disabled and reenabled developer mode and usb debugging, and restarted Unity and my phone several times. Any help with running this command in ubuntu or cmd, or even the greater problem of Unity Remote 5 would be fabulous.
Thank you.
Edit: here's a better image showing my issue:
image showing how I've tried to add the folder to the path but it still can't be reached
Final Update:
All my problems have been solved, here's how I got unity remote 5 for android working for posterity:
step 1) Make sure phone is in developper mode (go to "about phone" in settings, tap build number 7 times).
step 2) Make sure "USB debugging" is turned on in developer options.
step 3) Make sure Unity is updated to the most recent supported version through Unity Hub (might not be required but I did this step).
step 3) Download android support module through Unity Hub.
note: if you downloaded current Unity version from the Unity website rather than through Unity Hub, it doesn't seem to let you add modules to it through Unity Hub.
step 4) The sdk path Unity specifies by default is wrong for some reason, so in preferences->external tools, disable the default path and paste in the right directory (should be something like: C:\Program Files\Unity\Hub\Editors\2019.4.17f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK) to be safe I did this for the JDK, NDK and Gradle too.
step 5) When you plug in phone, pull down your notifications, hit "tap to change USB options" and make sure phone is in "camera" mode or some variation. For me it was "Photo transfer".
Note: if you don't have the option to change USB options, try different usb ports/cables, if those don't work you might have debris in your charging port, clean it out with a dab of 91% or 99% rubbing alcohol and a tooth brush/tweezers (this will also make charger sit more snug in phone)
That might be enough to get it working for you, if not...
step 6) (Not sure if necessary) May need to update phone drivers in device manager on windows.
step 7) If Unity gives an adb error saying too many devices connected, it's possible you have a daemon running in the background which adb is picking up as an android emulator because it's using a port greater than 5555. It seems adb checks open ports above port 5555, and assumes anything it finds is an emulator. To check this, as indicated in my original question, and as stated here: https://stackoverflow.com/a/39031464/14948855, in cmd on windows use adb devices (if ur on linux may need to use sudo) to get a list of all devices being detected by adb. (Also use "adb kill-server" to reset it.) If there is an emulator being detected, it should include the port it's using in its name, in my case it was "emulator-5562" in port 5562, which was apparently actually NTKDaemon from Native Instuments, a random music production program I've only used once so far. I'd suggest googling the emulator port you find to try and narrow down the process taking that port. The only thing left to do is to kill the process running in the port. I found NTKDaemon in task manager and also disabled it activating on startup because that's just evil imo.
And that should be it. Hope that works for you if you're here for help.
(btw in terms of my original question, I was able to access adb.exe by changing the directory in cmd, but I still never found why adding the directory to the path didn't work, so if anyone has an answer to that I would be interested)

Interact with SELinux on GenyMotion Virtual Device

I read a lot about SELinux, and I would have liked to try and get my hands on a case study for the university.
I have installed various virtual devices on GenyMotion, from Android 6 to Android 9, but nobody owns SElinux: when I do "sestatus" it answers "disabled".
I do not think it's enough to enable it, it seems that the modules must be installed in the kernel, can someone tell me how to do it? I tried but I did not find anything, I'm having a lot of difficulties, it's the first time I do these things.
Thanks to everyone in advance.
Finally I managed to make everything work: I was able to access Selinux information via a terminal in the GenyMotion virtual device. Selinux is already active on devices after version 4.3, there is no need to install it as it said #Martin Zeitler. I explain the solution to the problem (on Linux it works).
The first thing to do is to install a terminal in the virtual device: I have installed Termux. To do this, just download the apk from a site and drag it to the virtual device, the installation will start. Subsequently, it is necessary to provide the SuperUser permissions to the Termux terminal: banally, by opening the terminal, provide the SU command, and the device will ask you if you want to provide SuperUser permissions to the Termux application. When you enter the SU command, it will allow you to browse the folders on your device. With the "ls" command, providing the "-Z" option, you can see the SElinux context of the files. From the terminal, using the "getenforce" command, you can see how Selinux is running. Here you will see other useful commands: https://www.all-things-android.com/content/se-android-commands
Now, you will need to download the tool that allows us to interact with Selinux: setools. https://github.com/pasis/setools-android These tools are written in C, the native language of Android, so you need to download the NDK library to compile them: https://developer.android.com/ndk/downloads/
The first thing to do to compile, is to specify the project path:
export NDK_PROJECT_PATH=/my/project/path . The second step is to specify the makefile:
ndk-build NDK_APPLICATION_MK=/my/project/Makefile.am (for a complete guide: https://software.intel.com/en-us/articles/building-an-android-command-line-application-using-the-ndk-build-tools)
When you have finished compiling, you can send the Setools folder to the virtual device, using the adb program. ./adb push /setool/local/folder /remote/device/folder
(example: ./adb /setool /tmp) Now that you have Setool on your device, you can run the tools in the "/setool/obj/local/x86" folder. Thanks to "sepolicy-inject" you can also add rules to the policies.
Finally, thanks to this guide I realized that Selinux policies are stored in binary format, so it is not possible to interact with them without tools.
https://ge0n0sis.github.io/posts/2015/12/exploring-androids-selinux-kernel-policy/
one cannot "install SE Linux" on Android; because it's already installed and enabled by default since API level 21. you'd need to become user root, in order to access these management commands. this would only be possible on a rooted hardware device - or a rooted emulator image.
... just install CentOS or whatever else security enabled Linux distribution, for a test.

Unable to detect non-partitioned USB disk with NTFS file system on Android Marshmallow

Recently I ported marshmallow on my board. I was exploring USB functions and found an issue:
If I'm using a non-partitioned USB disk with NTFS file system, it's unable to detect it and display a notification as "Corrupted USB disk".
So I tried with other scenarios like, NTFS with partitioned USB disk, FAT32 on non-partitioned USB disk and all these are working fine.
Then I tried to mount it manually from adb shell:
# mount -t ntfs /dev/sda /mnt/usbdisk
and it's working fine.
But I'm still not able to find why it's not able to auto mount it when I've NTFS on non-partitioned USB disk.
Till now what all I came across is, my usb disk should be detected as DISK when non-partitioned but in case of NTFS file system it's taking it as PART i.e. partitioned disk and getting stuck somewhere.
Any suggestion or leads will be great help.
Thanks in Advance.
Please make few things....
U said ported to my board.
Talking about Android marshmallow or any other android ....
It is upon ur phone os to support NTFS file system.
Generally in stock Android there is no NTFS file system support.
Although it also depends upon brand , that they are providing NTFS file system support in their is or not.
Generally custom os ROM for ur phone may help.

Android - How to load HelloWorld app onto my Phone?

I made an Android Hello world app and I'm trying to load it onto my HTC Incredible. I believe it has 2.2 (how do I confirm that?)
Anyway, Eclipse gives me this message and then brings up the window in the screenshot below.
Automatic Target Mode: Unable to
detect device compatibility. Please
select a target device.
I'm on Ubuntu 64bit if that matters. I did turn on USB debugging on the phone. I told the phone to connect as a disk drive.
Any ideas how to get my app onto the phone?
Update: Do I need to perform these steps since I'm on Ubuntu? I doesn't mention what to do for Ubuntu 8.10 though.
Ok, it turns out I did have to follow all the instructions from this page. (The sudo stuff mentioned in other answers above didn't help.)
Here are the exact commands I ran for Ubuntu 8.10
You need to run the adb server in superuser mode (i.e. sudo adb start-server).
Try what EboMike said, run sudu adb start-server.
To answer your question "how do I confirm my phone is V2.2?" Press your phone's menu key, then settings, about phone, software information. The Android version is the number you're looking for. This shouldn't be important though for your hello world example.
Also, it's not important that you have the phone connect as a disk drive; this causes the SD card to be dismounted. It will actually cause problems if you run or debug an application that tries to access the SD card. You can just select charge only and use ADB/Eclipse's DDMS perspective to move files to and from the phone.
Here's an update answer in case anyone finds this thread from Google.
http://dimitar.me/how-to-connect-your-android-phone-to-ubuntu-to-do-developmenttestinginstallations-or-tethering/
The easiest way to this: Go to www.dropbox.com and sign up for a free account. Copy your .apk file from your project's /bin directory to your Dropbox. Download and install the free Dropbox app from the Android Market. Navigate to your .apk file on the Dropbox app and click it to download and install on your phone.
These are the steps I took on Arch Linux to resolve the same problem:
As mentioned in some of the other replies you will need a udev rule for the device. In this example I am using an HTC Desire.
(for HTC you'll need to use "0bb4")
Get the correct Vendor and Product IDs
run lsusb with the handset plugged in and you should see something like Bus 001 Device 004: ID 0bb4:0c87 High Tech Computer Corp. Desire (debug)
'0bb4' is the Vender ID: HTC
'0c87' is the Product ID
Make a udev rule using the values you've just retrieved
Now make a udev rule as root using:
$ sudo vim /etc/udev/rules.d/51-android.rules
Add the following (this is for HTC Desire - edit accordingly):
## Rule for an HTC Desire Android Phone
SUBSYSTEM=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0c87", MODE="0666", GROUP="users", NAME="HTC Desire"
GROUP defines which Unix group owns the device node.
At this point I rebooted and found that my handset was detected. Supposedly you can reload udev rules using the following but if this doesn't work try rebooting.
$ sudo udevadm control --reload-rules
in eclipse: go to Run menu -> Run configuration. Right click on android application on the right side and click new. Fill the corresponding details like project name under the android tab. Then under the target tab. Select launch on all compatible devices and then select active devices from the drop down list. Save the configuration and run it by either clicking run on the run button on the bottom right side of the window or close the window and run again
Cheers !

Android emulator doesn't use Windows host file?

m3 http://img245.imageshack.us/img245/461/65254534.jpg
Chrome using the windows' HOST file:
m1 http://img266.imageshack.us/img266/9380/59750633.jpg
Android emulator:
m2 http://img821.imageshack.us/img821/7363/19470766.jpg
edit
"On Windows, the emulator obtains the addresses by calling the GetNetworkParams() API. Note that this usually means that the emulator ignores the content of your "hosts" file (/etc/hosts on Linux/OS X, %WINDOWS%/system32/HOSTS on Windows)."
how can I use static IPs in the emulator?
I got this article, it explains how to edit the hosts file. I don't know if it works yet, bit it might help.
BROKEN (Feb 2015) - http://www.bradcurtis.com/2011/02/13/hosts-file-google-android-emulator/ (Leaving it in case it recovers)
If I'm not wrong, they moved the link here, I'm not sure if it's the same article, I haven't touched this since may 2012.
http://www.bradcurtis.com/hosts-files-and-the-google-android-emulator/ (Mirror Link https://web.archive.org/web/20180615121728/http://www.bradcurtis.com/hosts-files-and-the-google-android-emulator/)
EDIT: Adds a new link that works and talks about the ame issue (Not sure if it's the same article.
FWIW, it's not possible to change the phone's own /etc/hosts file within the emulator - it's on a read-only file system.
Personally, I'd run a local resolving server on your PC, point your Windows O/S at that, and then override the entries properly.
Unbound will do the job, and has a nice feature to allow you to insert "local data" into your DNS results.
It is possible to update the Android phone's own hosts file with:
adb remount
adb push hosts /etc/system/hosts (most tutorials suggest this file)
adb push hosts /system/etc/hosts (some VM systems seem to prefer this file instead!, for me this worked)
if any issues like i kept randomly getting a 'read-only file system' error 90
% of the time I tried running above, then try running 'adb root' before above (didnt work for me through), or start the Android VM manually with your android sdk's emulator.exe:
emulator.exe -avd Nexus_6_API_23 -partition-size 512
(some peeps recommended making partition size manually so can write to the VM easier?, eh seemed to work better but still got random read-only errors still).
An Android VM created with GenyMotion seemed much stabler and never get 'read only file system' issues with their VMs when i tried pushing the hosts file.
If the website you want to look at is hosted on your host machine, then you can point to it via a special IP android VMs recognize as the host machine via the hosts file:
10.0.2.2 test-drupal8.localhost
or if using Bridged Networking instead of NAT (pretend your windows host machine is 172.16.6.50 where your website is hosted and Android VM is 172.16.6.51), then can use windows ip directly:
172.16.6.50 test-drupal8.localhost
Note: make sure Windows Firewall/antivirus/firewalls are off if testing as they were blocking my urls until i turned them off.

Categories

Resources