Enabling MTP over USB using a user application

This section describes the steps to enable MTP over USB using a user application.

You can write your own application to enable MTP over USB. The application must call the MTP Client API to start the MTP server (in the MTP framework). The MTP Framework then loads the USB MTP Transport plug-in.

  1. The user application must instantiate a service provider, RMTPClient, and connect to the MTP Server.
  2. Once the session is connected start communication with the PC by calling StartTransport(). Pass the UID for the USB transport plug-in, 0x102827B2, to this method.
RMTPClient mtp; 
const TUid KUSBStillImage = { 0x102827B2 }; 

TInt err =  mtp.Connect();
if( err != KErrNone )
   {
   // Error in starting the MTP Framework
   }
else( err = mtp.StartTransport( KUSBStillImage ) )
   {
   if( err != KErrNone )
       {
       // Error in starting the USB transport.
       }
   }
...
err = mtp.StopTransport( KUSBstillImage ); 
if( err != KErrNone )
   {
   // Error in stopping the USB transport 
   }

mtp.Close();
Related tasks
Enabling MTP over USB