Downloading from the web using Download Manager Symbian API
Article Metadata
Code Example
Tested with
Compatibility
Article
Download Manager API can be used for handling download events, such as start, pause, and reset. It can also be used to move or delete downloaded content. For more details, see Download Manager API: Using the Download Manager API.
Contents |
Header files
#include <DownloadMgrClient.h> //for S60 3rd FP2, S60 5th EditionLibrary Files
LIBRARY DownloadMgr.lib
Code Snippet
Create a download manager session:
RHttpDownloadMgr iDMgr;
iDMgr.ConnectL( TUid::Uid( KThisAppUid ), *this, ETrue );
Create the UI Library Registry:
CDownloadMgrUiLibRegistry * iUiReg;
iUiReg = CDownloadMgrUiLibRegistry::NewL( iDMgr );
Install the User Interactions (dialogs) and get a pointer to them:
CDownloadMgrUiUserInteractions* idMgrUserInteractions;
idMgrUserInteractions = &iUiReg->RegisterUserInteractionsL();
Register a Downloads List:
CDownloadMgrUiDownloadsList * iMgrDownloadsList;
iMgrDownloadsList = &iUiReg->RegisterDownloadsListL();
The function HandleDMgrEventL() is called whenever a download begins, completes, pauses, or fails.
void CProgressiveDownloadAppUi::HandleDMgrEventL( RHttpDownload& aDownload,
THttpDownloadEvent aEvent )
{
switch ( aEvent.iDownloadState )
{
case EHttpDlCreated:
{
iMgrDownloadsList->DisplayDownloadsListL();
break;
}
case EHttpDlInprogress:
{
// iEikonEnv->InfoWinL(_L("Progress"),_L(" "));
break;
}
case EHttpDlCompleted:
{
iEikonEnv->InfoWinL(_L("Completed"),_L(" "));
break;
}
case EHttpDlFailed:
{
iEikonEnv->InfoWinL(_L("Failed"),_L(" "));
break;
}
case EHttpDlPaused:
{
//DownloadPausedL( aDownload, aEvent );
break;
}
default :
{
//iEikonEnv->InfoWinL(_L("Default"),_L(" "));
break;
}
}
}
Starting the Download
The URL from where the file has to be downloaded. The filename could be any location, even memory card (e:).
TBuf8<128> url = _L8("http://abc/movie.3gp");
TFileName filename(_L("c:\\data\\movie.3gp"));
iDMgr.SetStringAttribute(EDlAttrDestFilename,filename);
Create a new download subsession with the URL taken as the first parameter. isNewDl is true if Download is created. If the URL is already downloaded, it is set as false.
TBool isNewDl ;
RHttpDownload& dl = iDMgr.CreateDownloadL( url, isNewDl );
If isNewDl is true:
User::LeaveIfError( dl.Start() );
Closing the Download Manager session:
iDMgr.DeleteAll();
iDMgr.Close();


Jp4symbian - Devices supported
Hi,
Can you please mention the devices on which this code is successfully tested. I am facing some issues with Nokia N79 & E63.jp4symbian 15:22, 3 November 2011 (EET)
Hamishwillee - The ArticleMetaData says ....
Hi Jp4symbian
The ArticleMetaData (top right of page) says that this has been tested on Nokia 5800 XpressMusic, Nokia N97, Nokia N97 Mini. You might want to put a query on the discussion boards and cross link to this article for other devices. If you find any exceptions, please record them here.
Regards
Hamishhamishwillee 05:38, 4 November 2011 (EET)