问题
In Android 6.0, MTP no longer works automatically:
Device connections through the USB port are now set to charge-only mode by default. To access the device and its content over a USB connection, users must explicitly grant permission for such interactions. If your app supports user interactions with the device over a USB port, take into consideration that the interaction must be explicitly enabled.
MTP needs to be re-authorized at least every time you plug in the USB cable, and possibly more frequently than that (timeouts?).
With USB debugging enabled, the only solution that I have found to get MTP sharing to work on the device is to:
- Go into Settings > Developer options
- Scroll down to "Select USB Configuration"
- Switch the value of that option to anything but MTP, such as "Charging only" (if it is on MTP right now)
- Switch the value of that option to MTP
- Refresh your MTP client (e.g., on Ubuntu 15.04, close and re-open the window showing the contents of the device)
This is aggravating when you are trying to work with a device's files on external storage.
Is there a command-line way to get MTP going, short of writing a UIAutomator "test" that automates the above process? Or, is there some other way to get MTP to work without this sort of prep process?
回答1:
In Marshmallow (6.0 and 6.0.1) it is not possible without some sort of super power :-(
adb shell svc usb setFunction mtp
throws java.lang.SecurityException: Neither user 2000 nor current process has android.permission.MANAGE_USB.
and MANAGE_USB
is a signature|privileged
permission. I filed this as issue#193062. It has been put into state Assigned and labeled as Defect-25596495. It is fixed in N developer preview.
来源:https://stackoverflow.com/questions/33545537/how-do-we-toggle-on-mtp-more-easily-on-a-debug-enabled-android-6-0-device