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. Thanks for all your past and future contributions.

Revision as of 04:38, 30 May 2013 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to find Bluetooth device name by touching two NFC devices

From Wiki
Jump to: navigation, search
Article Metadata
Code ExampleTested with
Devices(s): Nokia C7-00
Created: mahbub_s60 (08 Jun 2011)
Last edited: hamishwillee (30 May 2013)



Near field communication (NFC) is not new technology but has received momentum after introducing NFC forum. NFC forum generates specification in such a way compatible devices are interoperable. NFC devices are integrated circuit (IC) that can generate magnetic field (Active) or can be induced by magnetic field (Passive). The magnetic field frequency is 13.56 Mz. The passive tag relies on the RF energy it receives to power the tag from active device. Any way we discuss more details about NFC/RF in separate article. In this article we are going to show and explain how we can use Symbian API to know the Bluetooth device name of another device.

Why we need to know Bluetooth address

Typically how we use Bluetooth devices? We start searching the devices with our Nokia devices and we wait a bit and get a list of devices and from there we select the device and get the address and then we can pair with other device by exchanging passkey and connect. This is a bit lengthy process. This time can be reduced dramatically by using NFC. Another most useful case, pairing with headset. We just touch headset with NFC phone and it is connected automatically.

Using Symbian API

To identify Bluetooth device, Symbian platform use AIW service API (AIW Criteria API). A resource is created based on the service command id (KAiwCmdNFCEasySetup) with other necessary parameters. The parameters can be generated also by code. In this example we are using resource to generate it.

RESOURCE AIW_INTEREST r_example_app_aiw_nfc_bt_interest
items =
id = 20001;
serviceCmd = KAiwCmdNFCEasySetup;
contentType = "*";
serviceClass = KAiwClassBase;
maxProviders = 1;

Now we can create AIW command with the following code.

iMyNfcBtHandler = CAiwServiceHandler::NewL();
iMyNfcBtHandler->ExecuteServiceCmdL( KAiwCmdNFCEasySetup, iMyNfcBtHandler->InParamListL(), iMyNfcBtHandler->OutParamListL(), KAiwOptASyncronous, this );

Now we get call back in our code where we can extract the Bluetooth device name.

TInt aCmdId,
TInt aEventId,
CAiwGenericParamList& aEventParamList,
const CAiwGenericParamList& aInParamList)
if( aCmdId == KAiwCmdNFCEasySetup )
for (int i = 0; (i < aEventParamList.Count()); i++)
TAiwVariant parameterValue = aEventParamList[i].Value();
switch (parameterValue.TypeId())
case EVariantTypeDesC8:
TPtrC8 data = parameterValue.AsData(); // data contains Device name, Address and CoD
TPtrC8 name = data.Mid(data.Length()-data[1], data[1]); // BT Device name
TPtrC8 data = parameterValue.AsData();
TPtrC8 name = data.Mid(data[1]+3, 6); // BTAddress
TBuf8<30> BtAdd(0);
_LIT8(KFormat, "0x%02x%02x%02x%02x%02x%02x");
BtAdd.Format(KFormat, name[0],name[1],name[2],name[3],name[4],name[5]);
Also note there is a bug in platform API, BT device name come 2 times

TBuf<50> Btname(0);
return KErrNone;

Example Code

The following code was used to test the API with two C7 devices. If we touch the devices each other it prints the Bluetooth device name of other device in UI. If we want to get notification every time, we have to generate AIW command each time.

This page was last modified on 30 May 2013, at 04:38.
37 page views in the last 30 days.