Android from A to Z: What lies behind the abbreviation MTP, and how to use it correctly

MTP ( Media Transfer Protocol ) first appeared on Android devices with Honeycomb . The protocol is slightly different from the usual USB Mass Storage ( UMS ), in which you turn on the USB mod and start moving files. And since MTP has become part of Ice Cream Sandwich on Galaxy Nexus , it would be nice to find out all the nuances. In this post we will try to understand as much as possible what exactly this protocol is, what is the need for it, and how to configure it to simplify file transfer.

How to enable Android MTP mode?

To do this, go to “Settings”, then to the “About phone - Device information” section and tap “Build number” 8 times. After this, a new section “For Developers” will appear in the settings at the very bottom above “About phone”. Go there, look for “USB Configuration” and set MTP

.

Interesting materials:

What to do if your dog is coughing? What to do if a dog attacks a cat? What to do if your dog barks at every sound? What to do if a dog barks on the street? What to do if your dog barks constantly? What to do if your dog starts to choke? What to do if your dog is choking and can’t clear his throat? What to do if your dog swallows a bone? What to do if your dog bites hard? What to do if the dog died?

What is MTP?

MTP is a set of custom extensions for PTP ( Picture Transfer Protocol ), which is aimed at transferring files and associated metadata over USB . Still here? Then let's continue.

Originally part of the Windows Media , but in 2008 MTP was standardized as a type of USB device, thereby becoming an established standard. If you have owned an iriver or Creative MP3 player, you have probably encountered MTP . RTR is involved , which is essentially the same as MTP . The thing is quite old, but not for Android .

MTP, external storage and your application

Some changes since Android 3.x may affect your app if you store data on external storage and want users to access those files from a PC or laptop.

Android 3.0 changed the means by which users mount external storage and make it available to the computer. Android previously used USB Mass Storage , the same protocol used by USB storage devices. This is why external storage was not available when the host machine mounted it - USB Mass Storage was not designed for smart storage devices.

Android now uses Media Transfer Protocol as a way to mount external storage. Much of what has been written about it is based on user experience, such as the need to use third party software to use MTP on OS X and Linux .

However, another important change for developers is that MTP content is not based on the literal content of external storage. Instead, the content in MTP is based on which files have been scanned by the MediaScannerConnection . If you write a file to external storage, then until the file is verified by MediaScannerConnection, it will not be visible to users via MTP.

External storage is scanned on reboot, and possibly periodically. Users can run a forced scan themselves using utilities such as SDRescan .

When you add files to the Android file system, those files are not automatically picked up by MediaScanner. It is best to use the scanFile() of the MediaScannerConnection to update the media database after the file is closed. This will immediately make the file available to the user. To do this, you need to add the following code:

Here the parameters are passed:

Previously we required a MediaScannerConnection for actual "media" such as MP3 or MP4 . Now it needs to be used for everything if we want to return the result to the user immediately. This means that you should also use MediaScanner for any files that a user might download onto their computer. It could be anything, for example. CSV files, PDF and so on. If the user might want to use them on the computer, you must make these files known using the methods described above.

Source

Direct modification and partial transfer functions

These functions can be used as more efficient alternatives to transferring and re-downloading the entire file:

From the MTP 1.1 specification:[5]

Operation codeOperation nameExplanation
0x9805GetObjectPropListMetadata transfer
0x9806SetObjectPropList
0x1019MoveObjectRename a file or directory
0x101BGetPartialObjectQuery the byte range of a file

Android extensions

According to go-mtpfs:[9]

Operation codeOperation nameExplanation
0x95C1GetPartialObject64Same as GetPartialObject
but with 64-bit offset
0x95C2SendPartialObjectSame as GetPartialObject64
but copying host to device
0x95C3TruncateObjectTrims the file to 64-bit length
0x95C4BeginEditObjectMust be called before using SendPartialObject
and
TruncateObject
0x95C5EndEditObjectCalled to commit changes made by SendPartialObject
and
TruncateObject

Why use MTP instead of USB Mass Storage?

The essence of using MTP is that now manufacturers of mobile devices do not need to create two separate partitions, one for applications, the second for media files. Previously, a sin was noticed behind them, which consisted in expanding the second partition at the expense of the first, and this very often led to a lack of space for new applications. With MTP, both types of files can be stored together.

USB Mass Storage has one big drawback - when you create memory partitions, one of them is completely at the mercy of the other device. This means that your tablet or smartphone will not have access to this section, but the computer to which the device is connected can manage it in every possible way. For this reason, some applications and, especially, widgets placed on the SD card do not work.

Another advantage of MTP is that there is no need to use the FAT file system for storage. This ultimately leads to faster operation of the device.

PTP - digital camera

PTP stands for Picture Transfer Protocol. When Android uses this protocol, it appears to the computer as a digital camera.

MTP is actually based on PTP but adds more features or "extensions". PTP works similar to MTP and is commonly used by digital cameras. Any program that supports capturing photos from a digital camera will support capturing photos from an Android phone when PTP mode is selected. PTP was designed to be the standard protocol for communicating with digital cameras.

In this mode, your Android device will work with digital camera applications that support PTP, but not MTP. Apple Mac OS X supports PTP, so you can use PTP mode to transfer photos from Android device to Mac via USB connection without any special software.

If you have an old Android device, you are forced to use a USB drive. On a modern Android device, you have a choice between MTP and PTP—you should use MTP unless you have software that only supports PTP.

If your device has a removable SD card, you can remove the SD card and insert it into your computer's SD card slot. The SD card will be available to your computer as a storage device, so you can access all the files on it, run file recovery software, and do everything you can't do with MTP.

Source

General recommendations for installing drivers for most Android devices

In principle, the automatic installation of the necessary drivers by the Windows operating system itself almost always works. However, you can also use alternative methods related to the installation of related utilities for a smartphone or tablet.

For example, the same Samsung MTP Device driver is installed automatically if you have the latest version of the Kies application. Please note that Samsung Corporation does not release drivers for each specific model of a mobile gadget, so looking for them, say, for the S6 or Galaxy Note 2 makes absolutely no sense.

For HTC smartphones, you need to use specialized software called HTC Sync Manager (sometimes you may need to install the firmware via FastBoot mode). For LG, you can find a driver on the manufacturer's official website specifically for a specific model. For Nexus, you need to use the ADB RUN utility and install the driver from the standard Device Manager. When using Sony gadgets, there are two options: installing Sony PC Suite or using FlashTool drivers. In principle, there is no difference, but you need to remember that these are two mutually exclusive programs - when installing one, you must first remove the other.

Installation of MTP

Since Windows XP MTP devices have been working seamlessly with Windows . Connect your Galaxy Nexus , select MTP as the connection type, the computer operating system itself finds the necessary drivers, you just need to wait a little. Moving files between your smartphone and PC without any problems is ensured. But what about those users who prefer Linux and Mac ?

MacOS

Android guys made this process as painless as possible. You just need to download and install the Android File Transfer , connect your device to your computer, launch the application and get started. You can drag and drop any files from or to the device, but each individual file must not exceed 4 GB in size.

Linux

With Linux some difficulties begin. You will not achieve the desired goal in one click, but you will be able to study in detail all the processes taking place. Don't despair, you'll just have to have a little fun with the command window. Here's how to use Galaxy Nexus with Ubuntu :

Install the UDEV rule by opening the rules file via terminal

sudo nano -w /etc/udev/rules.d/51-android.rules

Then enter the following line at the bottom of the file (remember to include your username):

SUBSYSTEM==»usb», ATTR{idVendor}==»04e8″, ATTR{idProduct}==»6860″, MODE=»0600″, OWNER=»»

After which it will be the turn for:

  • sudo apt-get install mtpfs
  • sudo mkdir /media/GNexus
  • sudo chmod 775 /media/GNexus

Then you should connect the Galaxy Nexus to the PC and in the same window enter:

sudo mtpfs -o allow_other /media/GNexus

This will all allow you to drag and drop files using Nautilus , and don't forget to enter the following command when you're done:

sudo umount mtpfs

Alternative

Alternatively, you can use a combination of Wifi File Explorer and QuickSSHd and send files wirelessly .

Related publications:

Tell me, I connected the tablet (galaxy tab 8.9) to the laptop, it says USB is connected and MTP is used. I downloaded the kit. Still can’t see the device. Help

You can open the memory card through Windows Explorer

When you connect your phone as USB Mass Storage, you give the phone’s flash drive for undivided use to the computer and it treats it as its own device, loads the driver for it, and operates with the file system structure. The computer driver is responsible for the integrity of the file system on the flash drive.

When you work via MTP, the computer works with the phone, and not with its flash drive, and works not as a data storage device, but as a separate peer device from which you can request files. All operations with the file system of the flash drive are performed by the phone itself at the request of the computer sent via MTP.

When working via MTP

Tell me, after updating the Android version to 5.0.2, when connecting to a PC, a message appears on the phone that it is connected as an MTP device. But now I don’t understand how to transfer the photo to the computer.

The bucket-heads are completely fucked up. Find, download, install a program to transfer a file to someone. Reminds me of the times of Uncle Liao, when each manufacturer required its own transfer program. No, thank you, I’d rather connect and transfer, connect and transfer, connect and transfer, until I get bored.

This is an explanation for at least a “Windows Media structure” specialist. I’m sure the author of this opus doesn’t even understand what he’s writing.

Source

Comparison with the USB storage protocol [edit | edit code ]

Unlike the USB disk protocol, MTP operates not on sectors, but on files. Thus, the player, connected as a flash drive, is completely trusted by the computer; connected via MTP - is independently responsible for the storage and integrity of data and, thus, can play some tracks simultaneously while recording others, prevent protected songs for which there are no rights, etc. [4]

Advantages [edit | edit code ]

  • Independence from the method of data storage. The player can store its information not only in a standard computer file system like FAT32 or NTFS, but also, for example, in an SQLite database.
  • Because of file-level transactional recording, the MTP device does not need a "safe eject"; it can be disabled at any time without losing data. The device itself will roll back (cancel and return to its original state) the transaction if it turns out that the connection is lost (the device is turned off, the computer is frozen, etc.).
  • Built-in support for tags, covers, ratings, etc.
  • Password access.
  • Remote music playback by commands from a computer.
  • The ability to use information from MTP devices in third-party applications - for example, for “scrobbling” [ unknown term
    ] songs played on the device to the Last.FM service.

Disadvantages [ edit | edit code]

  • Protocol complexity.
  • Low speed associated with transactional access.
  • In Windows, MTP is not a file system, but is supported at the application software level - therefore, “your favorite file manager” will not work. Requires Windows Media Player version 10; to support Ogg Vorbis - 11th. The antivirus will also not scan the connected player.
  • The player may refuse to store a particular file. Therefore, for example, to transfer the file archive.7z to the player, you have to rename it archive.7z.mp3.
  • Built-in copy protection support.
  • The file can only be rewritten as a whole and the size must be known at the time recording begins - therefore, you cannot work with an MTP device as flexibly as with a disk.
  • No multitasking - while one operation is running, others cannot be performed.
Rating
( 2 ratings, average 4 out of 5 )
Did you like the article? Share with friends:
For any suggestions regarding the site: [email protected]
Для любых предложений по сайту: [email protected]