Since Honeycomb, Android devices have starting using MTP (Media Transfer Protocol) instead of the straight up USB Mass Storage (UMS) file transfer system – creating massive headaches for most Linux users and not a few Windows users as well.  And since it’s become the standard since Ice Cream Sandwich and the Galaxy Nexus, it’s something any Linux & Android user is going to have to be able to cope with.  Fortunately, it’s quite easy to get this working.

First, you’ll need to install the MTP file system package:

$ sudo apt-get install mtpfs

Next you’ll need to create a static mount point for MTP attached devices:

$ sudo mkdir /media/MTPdevice
$ sudo chmod 775 /media/MTPdevice
$ sudo mtpfs -o allow_other /media/MTPdevice

If you don’t already know your device’s idVendor and idProduct, you can determine them by connecting your phone via USB and querying it using MTP.  Make sure your device is in MTP mode (PTP mode should work out of the box in Ubuntu 12.04 and up, but this only accesses your DCIM directory for your camera):

Android USB Computer connection dialog: MTP checked, PTP unchecked.

NOTE: if you can’t find the USB PC configuration under your settings, it’s possible that your phone has been set by the manufacturer or carrier to not show it.  You can use a dial code to change this settings instead.

Then query your device using MTP (this example uses a Galaxy Note II):

$ mtp-detect
libmtp version: 1.1.4

Listing raw device(s)
Device 0 (VID=04e8 and PID=6860) is a Samsung GT P7310/P7510/N7000/I9070/I9100/I9300 Galaxy Tab 7.7/10.1/S2/S3/Nexus/Note/Y.
   Found 1 device(s):
   Samsung: GT P7310/P7510/N7000/I9070/I9100/I9300 Galaxy Tab 7.7/10.1/S2/S3/Nexus/Note/Y (04e8:6860) @ bus 2, dev 20
Attempting to connect device(s)

As soon as the VID and PID appear you can cancel the command (CTRL-C).  If the VID and PID aren’t displayed immediately after the device is listed, MTP should eventually display “idVendor: 04e8″ and “idProduct: 6860″ in the output.

Next you’ll need to add a rule to your USB system handler to properly detect and mount your device using your favourite text editor as root:

$ gksu gedit /etc/udev/rules.d/51-android.rules

Add the following, on a single line (be sure to replace <vendorId> and <productId> with the values you got from mtp-detect):

SUBSYSTEM=="usb", ATTR{idVendor}=="<vendorId>", ATTR{idProduct}=="<productId>", MODE="0666"

After you save the file and exit your editor, disconnect your phone and restart udev:

$ sudo service udev restart

Now when you connect your Android phone, tablet, etc. it should automatically mount for you at /media/MTPdevice.

MTP File Explorer Showing Mounted Phone SD Cards

You’ll need to unmount it before disconnecting it, just like any other mounted volume.  You can either unmount from Nautilus or from the command line:

$ sudo umount mtpfs

Note that go-mtpfs may be more stable and ultimately easier to use, but since it’s more difficult to set up we’ve gone with the mtpfs solution here.

For those who are wondering why Google would create all this unnecessary hassle by changing up the USB access system, it’s mostly because MTP allows for simultaneous access on both the Android device and the connected PC, along with better file transfer support (ie, less file errors).

NOTE:

If you have your device locked (eg, which a swipe code or PIN), you’ll need to unlock it before your SD card(s) can be recognized by MTP and have it mount them for you to access locally.