Connect Android 3.0 and up to Ubuntu using the MTP-protocol

Modern android 3.0 3.1 and 4.0, 4.1 and 4.2 tablets and smartphones don't use the USB mass storage protocol anymore. They're using the GVFS protocol so they don't need to unmount the SD-card internaly.

Fot that it is a problem getting it hooked up to my Ubuntu machine.

This is because Google has moved away from the USB mass storage protocol, which was used up till Android 2.3, to the MTP (Media Transfer Protocol). As such, any phone or tablet with Android 3.0 and above will use the MTP protocol – something which doesn’t work too well with Ubuntu out of the box.

Upgrade Gvfs in Ubuntu 12.10 and 12.04 to get Android 4.0 support for devices which don't support USB Mass Storage interface

Use the PPA at your own risk! There are instructions on how to revert the changes at the down of the post.

1. To add the Gvfs (and libmtp) PPA created by the Gvfs MTP backend developer in Ubuntu 12.04 or 12.10, use the following commands:

sudo add-apt-repository ppa:langdalepl/gvfs-mtp sudo apt-get update

2. Then, launch Software Updater (previously known as Update Manager) and install the available updates.

3. Once everything has been updated successfully, restart your computer, unlock your Android device, connect it via USB and it should show up in your file manager (tested with Nautilus and Thunar 1.6).

4. If the Android device end up empty, be sure you unlocked it.

Revert the changes (purge the PPA)

To revert the changes (downgrade all the packages from our Gvfs PPA to the version available in the official Ubuntu repositories), firstly install PPA-Purge with multi-arch support from the main WebUpd8 PPA.

Then, purge the PPA using the following command:

sudo ppa-purge ppa:langdalepl/gvfs-mtp 

Wait for the packages to be downgraded successfully, restart the computer and everything should go back to the way it was before adding the Gvfs PPA above.

Old methods for the case this solution doesn't work:

It takes some tweaking to connect a MTP protocol using phone, but it works.

Read the long story here, or read on for the short solution.

There are 2 ways of connecting ubuntu using the MTP protocol.

The first one is relatively easy, but doesn't use the normal file browsers

gMTP

Ubuntu doesn’t come pre-installed with support for MTP, that’s why you can’t get your computer to see the phone after you have plugged it into the USB port.

gMTP is a simple MP3 and Media player client for MTP-based device. It provides a GUI for you to mount your Galaxy Nexus and transfer files in/out of it. We will need to compile some code in the process. Follow the steps below and you will be fine.

1. Open a terminal. Install libusb-dev

sudo apt-get install libusb-dev

2. We are going to need a copy of the libmtp file. The version in the Ubuntu repo is outdated, so we need to download the latest version of libmtp here. (For your info, I am using libmtp-1.1.2.tar.gz).

3. Extract the libmtp file to your Home folder. Back to the terminal:

cd libmtp-1.1.2 ./configure --prefix=/usr make sudo make install

This will compile and install the libmtp file.

4. Lastly, install gMTP

sudo apt-get install gmtp

Now, plug in your Galaxy Nexus and open gMTP. Press the Connect button. If successful, you should see the SD card folder of your Galaxy Nexus. You can now transfer files using the Add/Download button.

Note:

1. Even if it is connected in gMTP, your device won’t appear in the File Manager nautilus. You can manage your files transfer only in the gMTP GUI.

2. When attempting to download files from your phone, it will return an error saying the file is not found. This is because the default Download path has been to set to “/” (root) and you have no permission to write to the root folder. To change this, simply open the Preferences and change the Download path to “/home/username” or any other path that you desire.

The second method is more complex to install:

Connecting your Ice Cream Sandwich phone or tablet to Ubuntu for file access

Before you begin, try plugging your phone in and see if it works straight away. At the time of writing, the only official Android Ice Cream Sandwich phone is the Galaxy Nexus, and mine doesn’t work. But future ICS phones might work, depending on whether they have an SD card slot or not, and whether they support exporting the card as USB mass storage. If it works, you should be good to go.

First up, install the necessary tools:

sudo apt-get install mtp-tools mtpfs

Now, connect your Galaxy Nexus to your computer. On your phone, open up the notification drawer, and click on “USB Connection type”. Make sure that MTP is selected.

Then, run these commands:

mtp-detect | grep idVendor

mtp-detect | grep idProduct

You shall get an output with two ID's.

Note down the numbers written in front of idVenfor and idProduct, you’ll need those later on.

Now, run this commands:

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

A gedit window should open up. Type this text in it, all in a single line:

SUBSYSTEM=="usb", ATTR{idVendor}=="VENDORID", ATTR{idProduct}=="PRODUCTID", MODE="0666"

Replace VENDORID with the idVendor you had noted down earlier. Similarly, replace PRODUCTID with the idProduct you had noted down. In my case, they were 04e8 and 685c respectively on my GalaxyNexus and 18d1 and 4e41 on my Nexus 7, but they might have been different for you.

Also, remember to re-type the quotes in the line after you’ve copied and pasted it, otherwise udev may output an error.

Save and close the file. Then, disconnect your phone and run these commands:

sudo service udev restart

sudo mkdir /media/Nexus7

sudo chmod a+rwx /media/Nexus7

sudo adduser YOURUSERNAME fuse

Replace YOURUSERNAME with your Ubuntu user name. Now, run this command:

gksu gedit /etc/fuse.conf

In the Gedit window, remove the # at the beginning of the last line (the one that begins with “#user_allow_other”) like this:

You’re almost done! Now, restart your computer, and then run these three commands :

echo "alias android-connect=\"mtpfs -o allow_other /media/Nexus7\"" >> ~/.bashrc

echo "alias android-disconnect=\"fusermount -u /media/Nexus7\"" >> ~/.bashrc

source ~/.bashrc

Again, do re-type the quotes in each command after you’ve copied, otherwise the command won’t work.

Connect your phone again, and then make sure your phone is using MTP, then run this command:

android-connect

Voila! You can now browse your Android phone contents using Nautilus.

To safely remove the phone, just run the command:

android-disconnect

The connection is not a fast one. On my Nexus 7 I only get a data rate of abou 150 kb/s.