How to set Bluetooth power state
Article Metadata
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.
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
{
…
private:
virtual void DiscoverabilityModeChangedL(TBTDiscoverabilityMode aMode);
virtual void PowerModeChangedL(TBool aState);
virtual void BTAAccessoryChangedL(TBTDevAddr &aAddr);
virtual void BTAAConnectionStatusChangedL(TBool &aStatus);
private:
CBTMCMSettings* iBtSettings;
…
};
Source File
void CMyClass::ConstructL()
{
…
iBtSettings = CBTMCMSettings::NewL( this );
…
}
CMyClass::~CMyClass()
{
…
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 is for symbian 2nd edition phones,NOT for 3rd edition.
It's not true that changes to Central Repository are not propagated to the stack: in fact, they are. If you disable BT this way, it's going to be switched off.