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.

Checking the Bluetooth power state in 3rd Ed

From Wiki
Jump to: navigation, search
Article Metadata
Created: vin2ktalks (22 May 2007)
Last edited: hamishwillee (20 Jul 2012)
Reviewer Approved    Thumbs up icon sm.jpg

Headers Required:

#include <centralrepository.h> // for CRepository
#include <BTServerSDKCRKeys.h> // for KCRUidBluetoothPowerState, KBTPowerState
#include <BtnotifierAPI.h> // for KPowerModeSettingNotifierUid

Library Required:

LIBRARY centralrepository.lib  //CRepository

Source File:

//This will check the Bluetooth power state and if switched off
//then ask to switch it on.
TBool CBTEngine::CheckBluetoothPowerStateL()
return ETrue;
return TurnBluetoothOnL();
// ----------------------------------------------------------------------------
// CBTEngine::BluetoothPowerStateL()
// Get the Bluetooth power state of the device.
// ----------------------------------------------------------------------------
TBool CBTEngine::BluetoothPowerStateL()
CRepository* crep = CRepository::NewLC(KCRUidBluetoothPowerState);
TInt value = 0;
User::LeaveIfError(crep->Get(KBTPowerState, value));
return !(value == 0);
// ----------------------------------------------------------------------------
// CBTEngine::TurnBluetoothOnL()
// Uses the Notifier API to ask the user to turn on Bluetooth
// if it's not on already.
// ----------------------------------------------------------------------------
TBool CBTEngine::TurnBluetoothOnL()
RNotifier notifier;
User::LeaveIfError( notifier.Connect() );
TPckgBuf<TBool> dummy(ETrue);
TPckgBuf<TBool> reply(EFalse);
TRequestStatus status;
KPowerModeSettingNotifierUid, dummy, reply);
return reply();

Related Links

Note: The code has been taken from BTFileSend, an open source project in

Headline text

This page was last modified on 20 July 2012, at 07:48.
28 page views in the last 30 days.