2

On clicking a URL displayed in my application running on a Symbian S60 3rd Edition device should make the phone browser ( which is already open ) open the specified URL.

Here is the code:

_LIT( KUrlPrefix,"4 " )

void CMunduIMAppUi::OpenInBrowser(const TDesC& aUrl)
    {
    HBufC *url = NULL;
    const TInt KWmlBrowserUid =0x10008D39; 
    TUid id( TUid::Uid( KWmlBrowserUid ) );
    TApaTaskList taskList( CEikonEnv::Static()->WsSession() );
    TApaTask task = taskList.FindApp( id );

    // Checks if the browser is already open
    if ( task.Exists() )
        {
        HBufC8* parameter = HBufC8::NewL( aUrl.Length()+ KUrlPrefix().Length());
        parameter->Des().Copy(KUrlPrefix);
        parameter->Des().Append(aUrl);

        task.BringToForeground();
        task.SendMessage(TUid::Uid(0), *parameter); // UID not used

        delete parameter;
        parameter = NULL;
        }
    }

When I use this code to open a URL the browser comes to the foreground but does not get directed to the URL.

I suspect something is wrong in SendMessage call that is called after the browser is brought to foreground:

task.SendMessage(TUid::Uid(0), *parameter); // UID not used
ardsrk
  • 2,407
  • 2
  • 21
  • 33

5 Answers5

1

I've successfully used this code, that I believe I got from Forum Nokia:


    RApaLsSession apaLsSession;
    //Note that the UID of the OSS browser in S60 3rd Edition is 0x1020724D
    //and from S60 3rd Edition, FP1 onwards 0x10008D39.
    const TUid KOSSBrowserUidValue = {0x10008D39};
    //Parameter type 4: Start/Continue the browser specifying a URL =>
    //Parameter = "4"+" "+""
    _LIT(KParam4, "4 ");


    HBufC* param = HBufC::NewLC(KParam4().Length()+aUrl.Length());
    param->Des().Copy(KParam4);
    param->Des().Append(aUrl);

    //Find the browser application
    TUid id(KOSSBrowserUidValue);
    TApaTaskList taskList(iEikonEnv->WsSession());
    TApaTask task = taskList.FindApp(id);
    if(task.Exists())
        {
        //Continue the application
        task.BringToForeground();
        HBufC8* param8 = HBufC8::NewLC(param->Length());
        param8->Des().Append(*param);
        task.SendMessage(TUid::Uid(0), *param8); // UID not used
        CleanupStack::PopAndDestroy(param8);
        }
    else
        {
        if(!apaLsSession.Handle())
            {
            User::LeaveIfError(apaLsSession.Connect());
            CleanupClosePushL(apaLsSession);
            }
        //Start the application
        TThreadId thread;
        User::LeaveIfError(apaLsSession.StartDocument(*param, KOSSBrowserUidValue, thread));
        CleanupStack::PopAndDestroy(&apaLsSession);//   .Close();
        }
    CleanupStack::PopAndDestroy(param);

1

You can easily do it with Qt, if you don't mind a dependency on Qt.

QDesktopServices::openUrl(QUrl("http://yoursite.com/"));

Hope this helps.

Venemo
  • 18,515
  • 13
  • 84
  • 125
1

Maybe it would cooler to open the link inside your app instead:

    _LIT( KTestUrlPrefix,"4 " );
iOverriddenSettings = new (ELeave) TBrowserOverriddenSettings;
iOverriddenSettings->SetBrowserSetting( EBrowserOverSettingsSmallScreen, EBrowserOverFullScreenValueSoftKeysOnly);//(TUint) 1 );
iOverriddenSettings->SetBrowserSetting( EBrowserOverSettingsAutoLoadImages, (TUint) 1 );
iOverriddenSettings->SetBrowserSetting( EBrowserOverSettingsFontSize, (TUint) 0 );
iOverriddenSettings->SetBrowserSetting( EBrowserOverSettingsFullScreen, EBrowserOverFullScreenValueNormal);//(TUint) 0 );
iOverriddenSettings->SetBrowserSetting( EBrowserOverSettingsCustomAp, (TUint) iIAP ); //access point ID 


HBufC* parameter = HBufC::NewLC( KTestUrlPrefix().Length() + aLink.Length() );
parameter->Des().Copy( KTestUrlPrefix );
parameter->Des().Append( aLink );
if(iLauncher)
{
    delete iLauncher;
    iLauncher = NULL;
}
iLauncher = CBrowserLauncher::NewL();
iLauncher->LaunchBrowserEmbeddedL( *parameter, NULL, NULL, iOverriddenSettings );
CleanupStack::PopAndDestroy();
Riho
  • 4,523
  • 3
  • 33
  • 48
  • this worked. But I am concerned if the code could cause problems if I get my application Symbian Signed. See OpenWebBrowserL function here [ http://code.google.com/p/mobbler/source/browse/src/mobblerappui.cpp?spec=svn47607874e896e0ab6ca07d5207a4453c1c8e973b&r=77a6566e9ea3dc192c97a0e8c23edd613a50dce8 ] line number 2251 – ardsrk May 25 '10 at 09:00
  • I don't see any reason why it shouldn't be Symbian signed. Who knows why it was commented out in your sample. – Riho May 25 '10 at 10:36
1

Have you tried the Browser Launcher API which is documented here and can be downloaded here?

KevinD
  • 1,769
  • 10
  • 25
0

You need the SwEvent capability for TApaTask::SendMessage (but this is not mentioned in the documentation).