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. Thanks for all your past and future contributions.

How to set Bluetooth power state

From Wiki
Jump to: navigation, search
Article Metadata
Created: petrosoi (11 Apr 2007)
Last edited: hamishwillee (30 May 2013)

This document briefly explains how to change the Bluetooth device power state on a S60 3rd Edition device. The information in this document is provided as is and the code samples are not meant to be of commercial quality.

Note.pngNote: You need to download and install the Extensions plug-in package for S60 3rd Edition SDK for Symbian OS, for C++, MR, Version 3 from [1] to gain access to the needed APIs. At the time of writing, the API plugin is only available for S60 3rd MR.

The public S60 3rd Edition MR SDK includes an UID that can be utilized to toggle BT power state using a notifier. This approach however cannot handle the device discoverability setting correctly.

A better approach is to use the Bluetooth Engine API, available in the Extensions plugin mentioned above.

MBTMCMSettingsCB interface needs to be implemented and a pointer to the implementor must passed as an argument, when constructing the CBTMCMSettings object.

Code Snippet

Header File

#include <bteng.h> // bteng.lib
class CMyClass: publuc CBase, public MBTMCMSettingsCB

virtual void DiscoverabilityModeChangedL(TBTDiscoverabilityMode aMode);
virtual void PowerModeChangedL(TBool aState);
virtual void BTAAccessoryChangedL(TBTDevAddr &aAddr);
virtual void BTAAConnectionStatusChangedL(TBool &aStatus);
CBTMCMSettings* iBtSettings;


Source File

void CMyClass::ConstructL()

iBtSettings = CBTMCMSettings::NewL( this );


delete iBtSettings;

void CMyClass::DiscoverabilityModeChangedL(TBTDiscoverabilityMode aMode)
//Do something
void CMyClass::PowerModeChangedL(TBool aState)
//Do something
void CMyClass::BTAAccessoryChangedL(TBTDevAddr &aAddr)
//Do something
void CMyClass::BTAAConnectionStatusChangedL(TBool &aStatus)
//Do something
//In some function :
TInt err = iBtSettings->SetPowerState( EFalse ); // or ETrue…

Note that you can not change the power state through the central repository key: even though the key is writable, changes to it are not propagated to the stack.

For getting the Bluetooth Status (On/Off), we can use Central Repository in 3rd edition

CRepository *crepository = CRepository::NewL(KCRUidBluetoothPowerState);
TInt BluetoothStatus=0;
User::LeaveIfError( crepository->Get(KBTPowerState, BluetoothStatus) );
This page was last modified on 30 May 2013, at 23:27.
45 page views in the last 30 days.