×
Namespaces

Variants
Actions

Launching default application based on MIME type

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: antonypr (19 Apr 2007)
Last edited: hamishwillee (24 Jan 2012)

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.


Related:

This page was last modified on 24 January 2012, at 03:22.
58 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×