Filtering Bluetooth Devices
Article Metadata
This small code snippet shows how you can use the TBTDeviceClass to ensure that only a particular class of services and/or devices are found, when using RNotifier class.
RNotifier notifier;
User::LeaveIfError(notifier.Connect());
CleanupClosePushL(notifier);
TBTDeviceSelectionParamsPckg filter;
// Setting the filter, first the service class then the
// major and minor device class
TBTDeviceClass deviceFilter(EMajorServiceObjectTransfer,
EMajorDevicePhone,
EMinorDevicePhoneUnclassified |
EMinorDevicePhoneCellular |
EMinorDevicePhoneCordless |
EMinorDevicePhoneSmartPhone |
EMinorDevicePhoneWiredModem |
EMinorDevicePhoneCommonISDNAccess );
filter().SetDeviceClass(deviceFilter);
TBTDeviceResponseParamsPckg response;
TRequestStatus status;
notifier.StartNotifierAndGetResponse(status,
KDeviceSelectionNotifierUid,
filter,
response);
User::WaitForRequest(status);
if(status.Int() != KErrNone)
{
_LIT(KGetResponse, "StartNotifierAndGetResponse error %d");
console->Printf(KGetResponse, status.Int());
User::Leave(status.Int());
}
// Extracting the major and minor device class of the selcected device
TUint8 major = response().DeviceClass().MajorDeviceClass();
TUint8 minor = response().DeviceClass().MinorDeviceClass();
CleanupStack::PopAndDestroy(1); // RNotifier
The enumerations e.g. EMajorDevicePhone are defined in btdevice.h, you'll find additional enumerations you can used to create an appropriate filter in that header.


(no comments yet)