Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do we toggle on MTP more easily on a Debug-Enabled Android 6.0 device?

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?

like image 314
CommonsWare Avatar asked Nov 05 '15 13:11

CommonsWare


People also ask

How do I enable MTP on Android 6?

Reboot your device. Now go to "Settings-->Developer options" and enable "USB debugging". Then tap on "Select USB configuration" and select the option "MTP(Media Transfer Protocol)".

How do I turn off debug mode on Android?

Go to Settings. Tap System > Developer options. Go to USB debugging and flip the switch to turn it off.


1 Answers

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.

like image 189
cuihtlauac Avatar answered Oct 27 '22 00:10

cuihtlauac