How to prompt the user to select a remote device

When there are several suitable remote devices, you can want to prompt the user to pick the one to which a connection should be made. A dialog to do this is supplied. Note that the dialog is not provided by a standard dialog class as this would require a Bluetooth client to have its own UI, and for this to be brought to the foreground. Instead, clients request a background thread called the notifier server to create the dialog: the server can put a dialog over the UI of whatever application happens to have the foreground.

To use the dialog:

  1. Create an RNotifier object, and connect it with RNotifier::Connect()

  2. Call RNotifier::StartNotifierAndGetResponse() passing in:

  3. When the StartNotifierAndGetResponse() calls completes, extract the device information returned from its buffer.

  4. Clean up by cancelling and closing the notifier.

Example

// 1. Create a notifier
RNotifier not;
User::LeaveIfError(not.Connect());

// 2. Start the device selection plug-in
TBTDeviceSelectionParams selectionFilter;
TUUID targetServiceClass(0x2345);
selectionFilter.SetUUID(targetServiceClass);
TBTDeviceSelectionParamsPckg pckg(selectionFilter);
TBTDeviceResponseParams result;
TBTDeviceResponseParamsPckg resultPckg(result);
TRequestStatus status;
not.StartNotifierAndGetResponse(status, KDeviceSelectionNotifierUid, pckg, resultPckg);
User::After(2000000);

// 3. Extract device name if it was returned
User::WaitForRequest(status);
TPtrC name;
if (status.Int() == KErrNone)
    {
    if (resultPckg.IsValidDeviceName())
        {
     name.Set(resultPckg().DeviceName());
        }
    }
    
// 4. Clean up
not.CancelNotifier(KDeviceSelectionNotifierUid);
not.Close();