Launching default application based on MIME type
Article Metadata
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.
#include <APGCLI.H>
RApaLsSession session;
User::LeaveIfError(session.Connect());
CleanupClosePushL(session);
// Gets the UID and MIME type for the given file name.
TUid uid;
TDataType dataType;
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.
TThreadId threadId;
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.


09 Sep
2009
GUI application offen require to launching default application based on MIME type. For example opening image or audio/video files, it cane be launched by MIME type. RApaLsSession is right class to launch default application viewer as well as launching other applications.
This article described how to launching default application based on MIME type, how to launch other application based on UID, and what are different headers and library require to use RApaLsSession API.