Archived:Getting list of paired Bluetooth devices using Symbian C++
Article Metadata
Compatibility
Article
Overview
Getting a list of paired Bluetooth devices
Description
In order to retrieve a list of paired Bluetooth devices, design an Engine which derives from the "CActive" class.
Search for Bluetooth devices in the BT registry can be narrowed down with a TBTRegistrySearch instance.
The following code example uses the TBTRegistrySearch::FindBonded() criterion, which will return only Bluetooth devices that have already been paired with this device. Other criteria include searching by a specific device address, name, or Bluetooth device class. Search can be also be limited to return only trusted (authorized) devices.
Multiple search criteria can be used, in which case they are combined with the AND operator. TBTRegistrySearch::FindAll() will return all devices (unless other criteria are used).
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(); // of type CActiveSchedulerWait*
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( ®istry );
CleanupStack::PopAndDestroy( ®Server );
}
CActive::RunL() implementation of CBtEngine class:
void CBtEngine::RunL()
{
switch( iState )
{
case ENone:
break;
case ECreateView:
iSchedulerWait->AsyncStop();
break;
case EGetResponse:
iSchedulerWait->AsyncStop();
break;
default:
break;
}
}


Suggestion: make difference between FindAll and FindBonded more explicit
It may be worth adding an extra sentence or two about the difference between the FindAll() and FindBonded() filters, because FindAll() also seems to return some previously seen devices that are not visible to the user in the "paired devices" list.
At least to me it was non-obvious that this invisible information is persisted in the device database.
Thank you for your feedback. The article has been updated.
Forum Nokia KB 07:51, 25 September 2007 (UTC)
can't get CBTRegistryResponse->Start() actual result in FP1\FP2\5.0\N97 SDK
For all :
I have used the code build by 3.1(FP1) \ 3.2(FP2) \ 5.0 and N97 SDK But all SDK can't work when trying to use CBTRegistryResponse class 's Start() function. the iStatus will always return -2147483647 when finish the iScheduleWait event. Does the method work or there exist another necessary steps ? Thank very much.// ... all the same if ( retVal > 0 ) { CBTRegistryResponse* response = CBTRegistryResponse::NewL( registry ); CleanupStack::PushL( response ); response->Start( iStatus ); iState = EGetResponse; SetActive(); iSchedulerWait->Start(); retVal = iStatus.Int(); // the retVal will always return -2147483647 if ( retVal == KErrNone ) { RBTDeviceArray results = response->Results(); aDeviceArray.ResetAndDestroy(); ..... } ... }Rlaemmert - Same error here...
Is there any useful solution for that?rlaemmert 10:45, 22 July 2011 (EEST)