Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

S60第三版上启动浏览器并打开指定网页

From Wiki
Jump to: navigation, search
Article Metadata

兼容于
平台:
Symbian

文章
beover1984 在 25 Mar 2008 创建
最后由 hamishwillee 在 07 May 2013 编辑

我们通常使用下面的代码启动浏览器并打开指定网页:

void OpenUrlL(const TDesC& aUrl)
{
if(aUrl.Length() <= 0)
return;
 
HBufC* param = HBufC::NewLC( aUrl.Length() + 8 );
param->Des().Format( _L( "4 %S" ),&aUrl );
 
// Wap Browser's constants UId
const TInt KWmlBrowserUid = 0x10008D39;
TUid id( TUid::Uid( KWmlBrowserUid ) );
 
TApaTaskList taskList( CEikonEnv::Static()->WsSession() );
TApaTask task = taskList.FindApp( id );
if ( task.Exists() )
{
HBufC8* param8 = HBufC8::NewLC( param->Length() * 4 );
param8->Des().Append( *param );
task.SendMessage( TUid::Uid( 0 ), *param8 ); // Uid is not used
CleanupStack::PopAndDestroy(); // param8
}
else
{
RApaLsSession appArcSession;
User::LeaveIfError(appArcSession.Connect()); // connect to AppArc server
TThreadId id;
appArcSession.StartDocument( *param, TUid::Uid( KWmlBrowserUid ), id );
appArcSession.Close();
}
CleanupStack::PopAndDestroy(); // param
return;
}

然而在S60 3rd的设备上存在两个浏览器"网络"和"服务","网络"UID是0x1020724D,"服务"的UID是0x10008D39,上面的代码会启动"服务",但是确不能打开指定的网页,如果把UID换成"网络"的UID是可以正常打开的,可是在S60 3rd FP1的设备上只剩下一个浏览器,UID为0x10008D39,这就造成了代码通用性的问题,为了避免生成两个版本的程序,我们可以首先查找0x1020724D这个UID对应的程序是否在系统中存在,如果存在说明手机的基于S60 3rd的,如果不存那么就是基于S60 3rd FP1的,这时我们使用0x10008D39就可以了:

void OpenUrlL(const TDesC& aUrl)
{
if(aUrl.Length() <= 0)
return;
 
const TInt KBrowserUid1 = 0x1020724D;
const TInt KBrowserUid2 = 0x10008D39;
 
RApaLsSession appArcSession;
User::LeaveIfError(appArcSession.Connect()); // connect to AppArc server
 
HBufC* param = HBufC::NewLC( aUrl.Length() + 8 );
param->Des().Format( _L( "4 %S" ),&aUrl );
 
// Wap Browser's constants UId
TUid browserId( TUid::Uid( KBrowserUid1 ) );
 
TApaAppInfo appInfo;
if( appArcSession.GetAppInfo( appInfo, browserId ) != KErrNone )
{
browserId = TUid::Uid( KBrowserUid2 );
}
 
TApaTaskList taskList( CEikonEnv::Static()->WsSession() );
TApaTask task = taskList.FindApp( browserId );
if ( task.Exists() )
{
HBufC8* param8 = HBufC8::NewLC( param->Length() * 4 );
param8->Des().Append( *param );
task.SendMessage( TUid::Uid( 0 ), *param8 ); // Uid is not used
CleanupStack::PopAndDestroy(); // param8
}
else
{
TThreadId id;
appArcSession.StartDocument( *param, browserId, id );
}
 
appArcSession.Close();
CleanupStack::PopAndDestroy(); // param
return;
}

上面的代码在E50和N95上验证通过.

This page was last modified on 7 May 2013, at 23:59.
234 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.

×