×
Namespaces

Variants
Actions

How to set Bluetooth power state

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: petrosoi (11 Apr 2007)
Last edited: hamishwillee (31 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
{

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 page was last modified on 31 May 2013, at 02:27.
39 page views in the last 30 days.