I have previously asked a few questions regarding more 'programmatic' inquiry into Bluetooth Device Inquiry (i.e. not using the User Interface provided by RNotifier) and have seen the example code and instructions regarding RHostResolver and I am very thankful for those pointers. However, I seem to be running into a small problem.
I start with the usual example code, for my test case:
Then I successfully extract the devicename of the other BT device in my vicinity (I'm using the Emulator with BT card as the 'inquirer' and a Nokia 3650 as the other device). That is to say, the following code succeeds and properly prints the device's name.
TPtrC deviceName;
if (status == KErrNone)
deviceName.Set(entry().iName);
iEikonEnv->InfoMsg( deviceName );
However, I seem to be completely unable to extract the other device's Bluetooth Address. I am a bit unsure of where I should be looking? Do I extract the BT Address from the "entry" TNameEntry object like I have extracted the name? Would I do so in a fashion such as this:
TBTSockAddr testBTSockAddr = entry().iAddr;
I have tried that and it did not appear to succeed.
I suppose what I'm trying to ask is: after the proper completion of "RHostResolver::GetByAddress", while doing a Bluetooth Inquiry, where does the Bluetooth address of the remote device get placed and how do I properly extract it?
Well, seems that after a number of hours banging my head against it, I have come to a conclusion. I hope that my experience helps others.
First off: After GetHostByAddress is called, the Bluetooth address of the first remote device can be accessed by first creating a TBTSockADDR from the TNameEntry buffer:
TBTSockAddr iBTSockAddr( entry().iAddr);
And then using that object's .BTAddr() call as follows:
iBTSockAddr.BTAddr()
Which returns the TBTDevAddr.
I had a good deal of trouble with this because many bluetooth socket operations will fail, at least if the emulator is a client, if you leave a RHostResolver object open while trying to attempt them. For some reason, you must close any open RHostResolvers declared in that function block for things like socket connectivity to work and this was hindering my ability to test the proper inquiry of addresses.