You Are Here:

Community: Wiki

This page was last modified on 9 October 2008, at 17:36.

CS000910 - Prompting the user to select a Bluetooth device using RNotifier

From Forum Nokia Wiki



ID CS000910 Creation date April 22, 2008
Platform S60 3rd Edition, FP1 Tested on devices Nokia N95
Category Symbian C++ Subcategory Bluetooth


Keywords (APIs, classes, methods, functions): RNotifier,TBTDeviceSelectionParamsPckg,

TBTDeviceResponseParamsPckg,RNotifier::StartNotifierAndGetResponse(), RNotifier::CancelNotifier(),RNotifier::Close()

Overview

This code snippet describes the Bluetooth device discovery mechanism provided by the S60 UI platform. The RNotifier class can be used to perform device discoveries where user interaction is required. By using the TBTDeviceSelectionParams class it is also possible to restrict the search to a more specific subset of devices.

This snippet can be self-signed.

MMP file

The following libraries are required:

LIBRARY bluetooth.lib
LIBRARY btextnotifiers.lib
LIBRARY btdevice.lib

Header file

#ifndef BTDEVICEFINDER_H_
#define BTDEVICEFINDER_H_
 
#include <e32base.h>
#include <BTExtNotifiers.h> //TBTDeviceSelectionParamsPckg,TBTDeviceResponseParamsPckg
class MBTDeviceFinderNotify
{
public:
virtual void BTDeviceSelected() = 0;
};
 
class CBTDeviceFinder: public CActive
{
public:
static CBTDeviceFinder* NewL(const TInt aPriority,
MBTDeviceFinderNotify& aNotify);
~CBTDeviceFinder();
public:
void DiscoverDevicesL();
void SetSelectionParams(const TBTDeviceSelectionParams& aFilter);
const TBTDeviceResponseParams& ResponseParams();
protected:
void RunL();
void DoCancel();
private:
CBTDeviceFinder(const TInt aPriority,MBTDeviceFinderNotify& aNotify);
void ConstructL(void);
private:
RNotifier iSelectorNotifier;
MBTDeviceFinderNotify& iNotify;
TBTDeviceSelectionParamsPckg iSelectParamsBuf;
TBTDeviceResponseParamsPckg iResponseParamsBuf;
TBool iConnected;
};
#endif /*BTDEVICEFINDER_H_*/

Source file

#include "BTDeviceFinder.h"
 
CBTDeviceFinder::CBTDeviceFinder(const TInt aPriority,
MBTDeviceFinderNotify& aNotify)
:CActive(aPriority),iNotify(aNotify),iConnected(EFalse)
{
}
 
CBTDeviceFinder::~CBTDeviceFinder()
{
Cancel();
if (iConnected)
{
iSelectorNotifier.CancelNotifier( KDeviceSelectionNotifierUid );
iSelectorNotifier.Close();
}
}
 
CBTDeviceFinder* CBTDeviceFinder::NewL(const TInt aPriority,
MBTDeviceFinderNotify& aNotify)
{
CBTDeviceFinder* self = new (ELeave) CBTDeviceFinder(aPriority,aNotify);
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop();
return self;
}
 
void CBTDeviceFinder::ConstructL(void)
{
CActiveScheduler::Add(this);
}
 
void CBTDeviceFinder::DoCancel()
{
iSelectorNotifier.CancelNotifier( KDeviceSelectionNotifierUid );
}
 
void CBTDeviceFinder::RunL()
{
//the user has selected some device
if(iStatus.Int() == KErrNone)
{
iNotify.BTDeviceSelected();
}
else //an error has occurred
{
User::Leave(iStatus.Int());
}
}
 
void CBTDeviceFinder::DiscoverDevicesL()
{
if (!iConnected)
{
User::LeaveIfError(iSelectorNotifier.Connect());
iConnected = ETrue;
}
 
iSelectorNotifier.StartNotifierAndGetResponse(iStatus,
KDeviceSelectionNotifierUid,
iSelectParamsBuf,
iResponseParamsBuf);
SetActive();
}
 
void CBTDeviceFinder::SetSelectionParams(const TBTDeviceSelectionParams& aFilter)
{
iSelectParamsBuf = aFilter;
}
 
const TBTDeviceResponseParams& CBTDeviceFinder::ResponseParams()
{
return iResponseParamsBuf();
}


Using CBTDeviceFinder class

  • In the header file:
class CBTDeviceFinder;
 
class CTestingAppUi : public CAknAppUi, MBTDeviceFinderNotify
{
public:
//...
//from MBTDeviceFinderNotify
void BTDeviceSelected();
//...
private:
//...
CBTDeviceFinder* iFinder;
};
  • In the source file:
#include "btdevicefinder.h"
#include <btdevice.h> //TBTDeviceClass, TBTDeviceName
#include <bttypes.h> //TBTDevAddr
 
void CTestingAppUi::ConstructL()
{
CActive::TPriority priority(CActive::EPriorityUserInput);
iFinder = CBTDeviceFinder::NewL(priority, *this);
}
 
CTestingAppUi::~CTestingAppUi()
{
delete iFinder;
}
 
void CTestingAppUi::SelectDeviceL()
{
/* search only within a specific subset of devices
TBTDeviceSelectionParams selectionFilter;
TBTDeviceClass deviceFilter(EMajorServiceObjectTransfer, EMajorDevicePhone,
EMinorDevicePhoneUnclassified |
EMinorDevicePhoneCellular |
EMinorDevicePhoneCordless |
EMinorDevicePhoneSmartPhone |
EMinorDevicePhoneWiredModem |
EMinorDevicePhoneCommonISDNAccess );
 
selectionFilter.SetDeviceClass(deviceFilter);
iFinder->SetSelectionParams(selectionFilter);
*/

 
iFinder->DiscoverDevicesL();
}
 
void CTestingAppUi::BTDeviceSelected()
{
//Do something when BT device is selected
//e.g. get details of the device the user selected
//TBTDeviceResponseParams response = iFinder->ResponseParams();
//TBTDevAddr deviceAddress = response.BDAddr();
//TBTDeviceName deviceName = response.DeviceName();
//TBTDeviceClass deviceClass = response.DeviceClass();
}

Postconditions

The Bluetooth device selection dialog is shown to the user through the notifier framework.

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fBluetoothE5fProtocolX qdcZpublisherQUxhttpE3aE2fE2fswE2enokiaE2ecomE2fidE2fc764fd1cE2d8b06E2d499aE2d9a6aE2d17c3903d5a65E2fforumE5fnokiaE5fcrawlerE5fagentX qdcZtitleQSxBluetoothE20ProtocolE20E2dE20ForumE20NokiaE20WikiX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qrssZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qfnZdistributionQUxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2fX qfnZtopicQUqfnTopicZbluetoothQRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtopicQUqfnTopicZconnectivityQRqmarsZrelevanceQNx100X qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZupdatedQDx2008E2d10E2d02X qfnZuserE5ftagQSxbluetoothX qfnZuserE5ftagQSxconnectivityX qmarsZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ