Namespaces

Variants
Actions

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 over the next few weeks. Thanks for all your past and future contributions.

Checking the Bluetooth power state in 3rd Ed

From Wiki
Jump to: navigation, search
Article Metadata
Article
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:

//-----------------------------------------------------------------------------------
//CBTEngine::CheckBluetoothPowerStateL()
//This will check the Bluetooth power state and if switched off
//then ask to switch it on.
//------------------------------------------------------------------------------------
 
TBool CBTEngine::CheckBluetoothPowerStateL()
{
if(BluetoothPowerStateL())
{
return ETrue;
}
else
{
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));
CleanupStack::PopAndDestroy(crep);
 
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;
notifier.StartNotifierAndGetResponse(status,
KPowerModeSettingNotifierUid, dummy, reply);
User::WaitForRequest(status);
notifier.CancelNotifier(KPowerModeSettingNotifierUid);
notifier.Close();
 
return reply();
}


Related Links


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

Headline text

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

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×