Enabling MTP over USB using the Symbian USB Manager

This section describes the steps to enable MTP over USB using the Symbian USB Manager.

The USB Manager provides functions to enable MTP over USB.

  1. In the user application which requests USB services, create a USB Manager session by using the RUsb::Connect() function.

  2. Call the function RUsb::TryStart() and pass the personality ID of the USB Still Image Class to the method. For more information about Personality ID, see Discovering details of USB personalities
  3. The USB Manager automatically loads the USB Still Image Class Controller which is a client of the MTP server. The Controller starts the MTP server and asks it to load the USB MTP Transport plug-in.
RUsb usb;
TInt err = usb.Connect();
if( err != KErrNone)
   {
    // Error in connecting with the USB Manager
   }

// Find the personality that supports MTP USB SIC 
TInt personalityId(KErrNotFound);
RArray<TInt> personalityIds;

err = usb.GetPersonalityIds(personalityIds);
if ( err != KErrNone)
   {
   // Error handling
   }
        
TInt count = personalityIds.Count();    
for (TInt i(0); i < count; i++)
   {
   TBool supported(EFalse);
   err = usb.ClassSupported(personalityIds[i], KUsbMTPUsbSicClassControllerUID, supported);
   if (err != KErrNone)
      {
      // Error handling
      }

   if (supported)
      {
      personalityId = personalityIds[i];    
      break;
      }
   }
personalityIds.Close();

if (personalityId != KErrNotFound)
   {
   TRequestStatus status ;
   usb.TryStart(personalityId, status);
   User::WaitForRequest(status);
   if(status.Int() != KErrNone)
      {
       // Error in trying to start the MTP service
      }
    }
...

usb.Close();