Launching default application based on MIME type
This article explains how to launch default application to open a file based on its MIME type. For example, you can launch the default video player to open .3gp or .mp4 files or launch the default browser to open HTML files. In Windows programming, it is basically the equivalent of ShellExecuteEx function.
The class that you need to launch default application is RApaLsSession. There are basically two steps you need to do. The first step, you need to get the MIME type of your file by calling RApaLsSession::AppForDocument(). You will get the MIME type and also the UID of the application that is associated with the MIME type.
The second step, start the application using the MIME type or UID of the application. This can be done by calling RApaLsSession::StartDocument().
The code below shows how you can launch default application to view a file based on its MIME type.
// Gets the UID and MIME type for the given file name.
User::LeaveIfError(session.AppForDocument(aFileName, uid, dataType));
// Runs the default application using the MIME type, dataType.
// You can also use the UID to run the application.
User::LeaveIfError(session.StartDocument(aFileName, dataType, threadId));
CleanupStack::PopAndDestroy(); // session
To compile the code above you need to #include a header file apgcli.h and link against two libraries, apgrfx.lib and apmime.lib.
You do not need any capabilities to execute that code.