2

单击在 Symbian S60 3rd Edition 设备上运行的应用程序中显示的 URL 时,手机浏览器(已打开)应打开指定的 URL。

这是代码:

_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;
        }
    }

当我使用此代码打开 URL 时,浏览器会进入前台,但不会定向到 URL。

我怀疑浏览器进入前台后调用的 SendMessage 调用有问题:

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

5 回答 5

1

我已经成功使用了这个代码,我相信我是从诺基亚论坛获得的:


    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);

于 2010-05-24T09:54:08.727 回答
1

如果您不介意对 Qt 的依赖,您可以使用 Qt 轻松完成。

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

希望这可以帮助。

于 2010-05-24T10:57:12.033 回答
1

也许在您的应用程序中打开链接会更酷:

    _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();
于 2010-05-25T05:16:51.367 回答
1

您是否尝试过此处记录并可在此处下载的浏览器启动器 API ?

于 2010-05-25T08:46:07.700 回答
0

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

于 2010-10-28T14:57:02.050 回答