You Are Here:

Community: Wiki

This page was last modified on 20 September 2009, at 13:58.

Bluetooth Engine API

From Forum Nokia Wiki

Reviewer Approved   
Note!
This API is not part of the public SDK. It can be found in the SDK API Plug-in.


APIPurpose

The main purpose of Bluetooth Engine is to provide a higher-level abstraction API for Bluetooth applications and services.The Bluetooth Engine API provides access to MCM settings, Bluetooth device configurations and Bluetooth connection settings.

Header Files:

#include <bteng.h> 
#include <bttypes.h>
#include <btdevice.h>

Link against:

LIBRARY   bteng.lib  bluetooth.lib  btdevice.lib

CAPABILITY:

CAPABILITY   LocalServices WriteDeviceData //for Set API's

Use cases

-Get/Set the value of Bluetooth MCM settings in this device. The Bluetooth MCM settings include the Bluetooth power state, discoverability mode, search mode, local Bluetooth name and Bluetooth SAP enable state

-Get a list of the paired Bluetooth devices stored in the local Bluetooth registry.Bluetooth Engine retrieves the devices via Bluetooth registry client API. The list of devices will be ordered by locale standard collation.

-It adds/retrieves/modifies/deletes a device(s) into/from Registry and also Sets the device security.

Example code

1)Derive your class from MBTMCMSettingsCB and implement the functions in them.

2)Create an Object of CBTMCMSettings.

iBtSettings = CBTMCMSettings::NewL( this );

-Get All Settings:

TBool powerState;
TBTDiscoverabilityMode discoverabilityMode;
TBTSearchMode searchMode;
TBuf<50> localName;
TBool nameModifiedFlag;
TBTSapMode sapMode;
iBtSettings->GetAllSettings(powerState,discoverabilityMode,searchMode,
localName,nameModifiedFlag,sapMode);

-Get local Bluetooth Name

TBuf<50> localName;
iBtSettings->GetLocalBTName(localName);
CEikonEnv::InfoWinL(_L("BT Name"),localName);

-Set local Bluetooth Name

TBuf<50> localName;
CAknTextQueryDialog* dlg = CAknTextQueryDialog::NewL(localName);
CleanupStack::PushL(dlg);
TInt err = dlg->ExecuteLD(R_DATA_QUERY_DIALOG);
if(err)
{
iBtSettings->SetLocalBTName(localName);
}
else
{
CEikonEnv::InfoWinL(_L("name not Entered"),_L(""));
}
CleanupStack::Pop(dlg);

-Get Discoverability Mode

TBTDiscoverabilityMode discoverabilityMode;
iBtSettings->GetDiscoverabilityMode(discoverabilityMode);
if(discoverabilityMode == EBTDiscModeHidden)
{
CEikonEnv::InfoWinL(_L("BlueTooth Discoverability"),_L("Hidden"));
}
else if(discoverabilityMode == EBTDiscModeGeneral)
{
CEikonEnv::InfoWinL(_L("BlueTooth Discoverability"),_L("General"));
}
else
{
CEikonEnv::InfoWinL(_L("BlueTooth Discoverability"),_L("Temporary"));
}

-Set Discoverability Mode

TBTDiscoverabilityMode discoverabilityMode(EBTDiscModeHidden);
//Can be EBTDiscModeGeneral or EBTDiscModeTemporary
iBtSettings->SetDiscoverabilityModeL(discoverabilityMode);

-Get Search Mode

TBTSearchMode searchMode;
iBtSettings->GetSearchMode(searchMode);
if(searchMode ==EBTSearchModeGeneral)
{
CEikonEnv::InfoWinL(_L("BlueTooth SearchMode"),_L("General"));
}
else
{
CEikonEnv::InfoWinL(_L("BlueTooth SearchMode"),_L("Limited"));
}

-Set Search Mode

TBTSearchMode searchMode(EBTSearchModeGeneral);//Can be EBTSearchModeLimited
iBtSettings->SetSearchMode(searchMode);

-Get Power State

TBool powerState;
iBtSettings->GetPowerState(powerState);
if(powerState)
{
CEikonEnv::InfoWinL(_L("BlueTooth On"),_L(""));
}
else
{
CEikonEnv::InfoWinL(_L("BlueTooth Off"),_L(""));
}

-Set Power State

iBtSettings->SetPowerState(ETrue);
//ETrue for Switching On, EFalse for Switching Off.

-Get BTSap Mode

TBTSapMode sapMode;
iBtSettings->GetBTSapEnableState(sapMode);
if(sapMode == EBTSapDisabled)
{
CEikonEnv::InfoWinL(_L("BlueTooth SAPMode"),_L("Disabled"));
}
else
{
CEikonEnv::InfoWinL(_L("BlueTooth SAPMode"),_L("Enabled"));
}

-Set BTSap Mode

TBTSapMode sapMode(EBTSapEnabled);//EBTSapDisabled
iBtSettings->EnableBTSap(sapMode);

Bluetooth Address of a device can be obtained by *#2820# star-hash code

RBTiDeviceHandler iDeviceHandler;

-Get List of paired devices

RBTDeviceHandler deviceHandler;
CBTDeviceArray* selectedDeviceArray = new (ELeave) CArrayPtrFlat<CBTDevice>(4);
CleanupStack::PushL(selectedDeviceArray);
TInt err = deviceHandler.GetPairedDevicesL(*selectedDeviceArray);
if(err == KErrNone)
{
TBuf<50> deviceName;
for(TInt i = 0 ; i<selectedDeviceArray->Count();i++)
{
deviceName.Copy(selectedDeviceArray->At(i)->DeviceName());
CEikonEnv::InfoWinL(_L("Device"),deviceName);
}
}
else
{
TBuf<50> errBuf;
errBuf.AppendNum(err);
CEikonEnv::InfoWinL(_L("Err"),errBuf);
}
CleanupStack::PopAndDestroy(selectedDeviceArray);

-Add a Device into Registry

//000000000000 is Bluetooth Device Address in decimal which 
// is unique to a device
 
TInt64 lBTIntAddr = 000000000000;
TBTDevAddr lBTDevAddr(lBTIntAddr);
CBTDevice* lBTDevice = CBTDevice::NewL(lBTDevAddr);
TInt lErr = iDeviceHandler.AddDeviceIntoRegistryL(*lBTDevice);
TBuf<50> errBuf;
errBuf.AppendNum(lErr);
 
if ( lErr == KErrNone )
{
CEikonEnv::InfoWinL(_L("added to registry"),errBuf);
}
else
{
CEikonEnv::InfoWinL(_L("Err"),errBuf);
}

-Get a Device from the Registry

//000000000000 is Bluetooth Device Address in decimal which 
// is unique to a device
 
TInt64 lBTIntAddr = 000000000000;
TBTDevAddr lBTDevAddr(lBTIntAddr);
CBTDevice* lBTDevice = CBTDevice::NewL();
TInt lErr = iDeviceHandler.GetDeviceFromRegistryL(*lBTDevice, lBTDevAddr);
if ( lErr == KErrNone )
{
// using lBTDevice, one can retrieve DeviceName,
// its FriendlyName and its Bluetooth Address
 
//sample code for retrieving DeviceName
 
TBuf8<20> lDeviceName8 = lBTDevice->DeviceName();
TBuf<20> lDeviceName16;
lDeviceName16.Copy(lDeviceName8);
 
EikonEnv::InfoWinL(_L("Device Name"), lDeviceName16);
}
else
{
TBuf<50> errBuf;
errBuf.AppendNum(lErr);
CEikonEnv::InfoWinL(_L("Err"),errBuf);
}

-Getting Devices from Registry

CBTDeviceArray* lSelectedDeviceArray = new (ELeave) 
CArrayPtrFlat<CBTDevice>(10);
CleanupStack::PushL(lSelectedDeviceArray);
TInt err = iDeviceHandler.GetDevicesFromRegistryL(*lSelectedDeviceArray);
if(err == KErrNone)
{
TBuf<50> deviceName;
for(TInt i = 0 ; i<lSelectedDeviceArray->Count();i++)
{
deviceName.Copy(lSelectedDeviceArray->At(i)->DeviceName());
CEikonEnv::InfoWinL(_L("Device"),deviceName);
}
}
else
{
TBuf<50> errBuf;
errBuf.AppendNum(err);
CEikonEnv::InfoWinL(_L("Err"),errBuf);
}
CleanupStack::PopAndDestroy(lSelectedDeviceArray);

-Delete a Device from Registry

//000000000000 is Bluetooth Device Address in decimal which 
// is unique to a device
 
TInt64 lBTIntAddr = 000000000000;
TBTDevAddr lBTDevAddr(lBTIntAddr);
CBTDevice* lBTDevice = CBTDevice::NewL(lBTDevAddr);
TInt lErrDel = iDeviceHandler.DeleteDeviceFromRegistryL(*lBTDevice);
 
if ( lErrDel == KErrNone )
{
CEikonEnv::InfoWinL(_L("deletion"),_L("successful"));
}
else
{
TBuf<50> errBuf;
errBuf.AppendNum(lErr);
CEikonEnv::InfoWinL(_L("deletion Err"),errBuf);
}

-Modify a Device in Registry

//000000000000 is Bluetooth Device Address in decimal which 
// is unique to a device
 
TInt64 lBTIntAddr = 000000000000;
TBTDevAddr lBTDevAddr(lBTIntAddr);
CBTDevice* lBTDevice = CBTDevice::NewL(lBTDevAddr);
TBuf<10> lDevFrdName(_L("XYZ"));
lBTDevice->SetFriendlyNameL(lDevFrdName);
TInt lErrMod = iDeviceHandler.ModifyDeviceInRegistryL(*lBTDevice);
 
if ( lErrMod == KErrNone )
{
CEikonEnv::InfoWinL(_L("modification"),_L("successful"));
}
else
{
TBuf<50> errBuf;
errBuf.AppendNum(lErrMod);
CEikonEnv::InfoWinL(_L("modification Err"),errBuf);
}

-Set Device Security

//000000000000 is Bluetooth Device Address in decimal which 
// is unique to a device
 
TInt64 lBTIntAddr = 000000000000;
TBTDevAddr lBTDevAddr(lBTIntAddr);
CBTDevice* lBTDevice = CBTDevice::NewL(lBTDevAddr);
TInt lErr = iDeviceHandler.SetDeviceSecurityL(*lBTDevice, ETrue,ETrue,ETrue);
TBuf<50> errBuf;
errBuf.AppendNum(lErr);
 
if ( lErr == KErrNone )
{
CEikonEnv::InfoWinL(_L("security settings"),errBuf);
}
else
{
CEikonEnv::InfoWinL(_L("Err"),errBuf);
}


Example project

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fBluetoothE5fE45ngineE5fAPIX qdcZpublisherQUxhttpE3aE2fE2fswE2enokiaE2ecomE2fidE2fc764fd1cE2d8b06E2d499aE2d9a6aE2d17c3903d5a65E2fforumE5fnokiaE5fcrawlerE5fagentX qdcZtitleQSxBluetoothE20E45ngineE20APIE20E2dE20ForumE20NokiaE20WikiX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qrssZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qfnZdistributionQUxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2fX qfnZtopicQUqfnTopicZbluetoothQRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtopicQUqfnTopicZconnectivityQRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtopicQUqfnTopicZseriesE5f60QRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZupdatedQDx2008E2d10E2d02X qfnZuserE5ftagQSxbluetoothX qfnZuserE5ftagQSxconnectivityX qfnZuserE5ftagQSxs60X qfnZuserE5ftagQSxs60btX qmarsZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ
User Rating: qfnZuserE5FratingQNx4E2E0000X