×
Namespaces

Variants
Actions

获得蓝牙设备匹配列表

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

文章
hoolee 在 15 Feb 2008 创建
最后由 hamishwillee 在 15 Dec 2011 编辑

为了获取蓝牙设备匹配列表,可以设计一个派生于CActive类的引擎来处理

void CBtEngine::GetPairedDevices( CBTDeviceArray& aDeviceArray )
 
{
 
RBTRegServ regServer;
 
RBTRegistry registry;
 
User::LeaveIfError( regServer.Connect() );
 
CleanupClosePushL( regServer );
 
User::LeaveIfError( registry.Open(regServer) );
 
CleanupClosePushL( registry );
 
TBTRegistrySearch searchPattern;
 
searchPattern.FindBonded();
 
registry.CreateView( searchPattern, iStatus );
 
iState = ECreateView;
 
SetActive();
 
iSchedulerWait->Start();
 
TInt retVal = iStatus.Int();
 
if ( retVal > 0 )
 
{
 
CBTRegistryResponse* response = CBTRegistryResponse::NewL(registry);
 
CleanupStack::PushL(response);
 
response->Start( iStatus);
 
iState = EGetResponse;
 
SetActive();
 
iSchedulerWait->Start();
 
retVal = iStatus.Int();
 
if ( retVal == KErrNone )
 
{
 
RBTDeviceArray results = response->Results();
 
aDeviceArray.ResetAndDestroy();
 
// RBTEngUtil::SortBTDevicesByNameL( results );
 
 
 
TInt count = results.Count();
 
for ( TInt i = 0; i < count; i++ )
 
{
 
aDeviceArray.AppendL( results[i]->CopyL() );
 
}
 
}
 
CleanupStack::PopAndDestroy( response );
 
}
 
CleanupStack::PopAndDestroy( &registry );
 
CleanupStack::PopAndDestroy( &regServer );
 
}

将iSchedulerWait按如下方式定义:

CActiveSchedulerWait* iSchedulerWait; // CActiveSchedulerWait instance
 
in the "RunL" of the active object:
 
void CBtEngine::RunL()
 
{
 
switch( iState )
 
{
 
case ENone:
 
break;
 
case ECreateView:
 
iSchedulerWait->AsyncStop();
 
break;
 
case EGetResponse:
 
iSchedulerWait->AsyncStop();
 
break;
 
default:
 
break;
 
}
 
}
This page was last modified on 15 December 2011, at 08:49.
23 page views in the last 30 days.