This section explains how to share a file using the Application Interworking (AIW) Service Handler API.
The AIW Service Handler API listens to NFC connections and provides data to the callback method.
The NFC AIW API provides the following
callbacks via MAiwNotifyCallback::HandleNotifyL()
:
NFC power on: This callback is called with the KAiwCmdNFCGive
command and the KAiwEventStarted
event identifier. The event parameter contains one parameter with
the semantic id KNfcSemanticIdNfcPowerInfo
and value KNfcPowerOn
.
NFC sharing started: This callback is called when NFC
connection hand over is complete and Bluetooth bearer connection is
up. It is called with theKAiwCmdNFCGive
command and
the KAiwEventStarted
event identifier, the event
parameter list is empty. The application is then expected to provide
the item(s) currently in focus to the NFC AIW provider. RFile
or RArray
types are supported and need to be stored
into the AiwGenericParamList& aInParamList
parameter
of the ExecuteServiceCmdL
method.
KAiwCmdNFCGive
command
and the KAiwEventStarted
event identifier. The event
parameter contains one parameter with semantic id KNfcSemanticIdNfcPowerInfo
and error value.Error Values |
Description |
---|---|
KErrHardwareNotAvailable |
NFC feature is not available or turned OFF by user. Sharing is not possible. The client application should instruct the user to turn the NFC ON. |
KErrAbort |
Bluetooth could not be enabled in offline mode. Sharing is not possible. |
System wide error values |
Error occurred during transfer or during prepare phase.
Call |
Note: Errors related to KAiwCmdNFCEasySetup
command is called back with KAiwEventError
and
empty parameter list.
NFC sharing completed: The HandleNotifyL()
callback is called after the file is sent and the NFC transfer is
completed. It is called with the KAiwCmdNFCGive
command
and the KAiwEventCompleted event identifier, the
event parameter list is empty. The application can then send another
file or if the transfer is completed it must release the connection
by calling the Reset()
method on CAiwServiceHandler
object.
Define an AIW_INTEREST
resource element in the resource file using KAiwCmdNFCGive
as a service command and KAiwClassBase
as a service class:
RESOURCE AIW_INTEREST r_example_app_aiw_nfc_interest { items = { AIW_CRITERIA_ITEM { id = 200000; serviceCmd = KAiwCmdNFCGive; contentType = "*"; serviceClass = KAiwClassBase; maxProviders = 1; } }; }
Include aiwcommon.h
and AiwServiceHandler.h
header
files in the application source files, and link to the servicehandler.lib
library in the MMP file.
Call the ExecuteServiceCmdL
method without providing AIW input parameters
to initiate listening to NFC callbacks, as shown in the following
code snippet:
iAiwServiceHandler = CAiwServiceHandler::NewL(); iAiwServiceHandler->AttachL( R_EXAMPLE_APP_AIW_NFC_INTEREST ); iAiwServiceHandler->ExecuteServiceCmdL( KAiwCmdNFCGive, iAiwServiceHandler->InParamListL(), iAiwServiceHandler->OutParamListL(), KAiwOptASyncronous, this );
Implement MAiwNotifyCallback::HandleNotifyL()
(declared in aiwcommon.h
) to receive callback notifications, as shown
in the following sample code snippet:
TInt CExampleApplication::HandleNotifyL( TInt aCmdId, TInt aEventId, CAiwGenericParamList& aEventParamList, const CAiwGenericParamList& /*aInParamList*/) { If ( aCmdId == KAiwCmdNFCGive ) { if ( aEventId == KAiwEventStarted ) { if( aEventParamList.Count() > 0 ) { TAiwGenericParam param = aEventParamList[0]; if ( param.SemanticId() == KNfcSemanticIdNfcPowerInfo ) { if( param.Value() == KNfcPowerOn ) { // NFC is powered on and Bluetooth is enabled } } else { // NFC connection detected, give in a RFile handle to the // file to be sent iInParamList = CAiwGenericParamList::NewL(); TAiwGenericParam obj( EGenericParamFile, TAiwVariant( iRFile ) ); iInParamList->AppendL( obj ); // Send the file via NFC (asynchronous) iAiwServiceHandler->ExecuteServiceCmdL( KAiwCmdNFCGive, *iInParamList, iAiwServiceHandler->OutParamListL(), KAiwOptASyncronous, this ); } } else if ( aEventId == KAiwEventCompleted ) { // NFC transfer completed – release touch iAiwServiceHandler->Reset(); delete iInParamList; iInParamList = NULL; } else // KAiwEventError { // In case of transfer failure release must be done. // For preparation failure resetting is not necessary if( aEventParamList.Count() > 0 ) { TAiwGenericParam param = aEventParamList[0]; if ( param.SemanticId() == KNfcSemanticIdError ) { if( param.Value() == KErrHardwareNotAvailable ) { // NFC not enabled. Reset must be called } else if( param.Value() == KErrAbort ) { // Bluetooth could not be enabled in offline mode. // } else { // other error } } else { // unspecified } } iAiwServiceHandler->Reset(); delete iInParamList; iInParamList = NULL; } } return KErrNone; }
The file or data is shared between the two devices.