How to access an MTP USB device with python

时间秒杀一切 提交于 2019-11-27 14:43:52

问题


How can I read from and write to my Galaxy Nexus phone, using MTP over a USB cable in python? I'm on a windows 7 computer.


回答1:


I'm also looking for the same thing. There seems to be pymtp for cross-platform and wmdlib for Windows.




回答2:


Calibre, a popular ebook management program, has python and C source code to transfer files over an MTP connection. http://code.google.com/p/calibre-ebook/downloads/list




回答3:


One way to do this would be to install ADB (android debugging bridge, part of the SDK) and launch it as a child process from python. ADB can be used to, among other things, read from or write to, an android device.




回答4:


Simply connecting a USB cable between the phone and computer should work.

It may be necessary to enable MTP transfers in the settings menu on your phone. The menu selection location is likely to be different on different versions of android and different phone models. Try a google search for "galaxy nexus enable mtp". Make sure to include your android and phone version in the search.

Make sure it is a good quality USB cable. Poor quality cables will not make a good connection and therefor not work reliably.

A file management dialog comes up immediately on my desktop after hooking up a usb cable between my phone and laptop showing both the phone internal storage and SD card. This allows me to transfer files both ways directly to the phone SD storage (Linux Mint <-> LG Android ver. 5.1)

Note that it is also possible to transfer files using Bluetooth.

After establishing a connection, you would need to find the device name. Then it would be possible to open the device using standard python file constructs, i.e. popen(), etc.



来源:https://stackoverflow.com/questions/11161747/how-to-access-an-mtp-usb-device-with-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!