Skip to content

Modules.Nfc.NfcForegroundDispatchFilter

A filter specifying intent, intent filters and technology lists used to match dispatch intents.

The Modules.Nfc.NfcAdapter.enableForegroundDispatch method is used to give priority to the foreground activity when dispatching a discovered tag to an application. This proxy is used to specify the intent, intent filters, and technology lists used to filter the dispatched intents. This proxy automatically creates the required pending intent and will create an intent for the current activity if one is not provided.

Use the Modules.Nfc.createNfcForegroundDispatchFilter method to create a foreground dispatch filter.

See also: enableForegroundDispatch

Extends: Titanium.Proxy · Since: 1.0.0 · Platforms: android

Properties #

intent#

Type: Titanium.Android.Intent

The intent to start the dispatch when matched.

This optional property allows you to override the default behavior for dispatching the
intent. If an intent is not provided (the default behavior), then an intent based on the current
activity is automatically created with a flag of FLAG_ACTIVITY_SINGLE_TOP.

intentFilters#

Type: Array<NfcIntentFilter>

The intent filters to override dispatching for, or null to always dispatch.

techLists#

Type: Array<Array<String>>

The tech lists used to perform matching for dispatching the ACTION_TECH_DISCOVERED intent.

Examples #

Foreground Dispatch filter

This example creates a dispatch filter used to filter NDEF messages that are of mime type 'text/plain' or URI from 'http://www.appcelerator.com'. Additionally, the filter will match tags with the specified technologies. The dispatch filter is then used when calling the `enableForegroundDispatch` API of the <Modules.Nfc.NfcAdapter> proxy.

dispatchFilter = nfc.createNfcForegroundDispatchFilter({
    intentFilters: [
        { action: nfc.ACTION_NDEF_DISCOVERED, mimeType: 'text/plain' },
        { action: nfc.ACTION_NDEF_DISCOVERED, scheme: 'http', host: 'www.appcelerator.com' }
    ],
    techLists: [
        [ "android.nfc.tech.NfcF", "android.nfc.tech.NfcA", "android.nfc.Ndef" ],
        [ "android.nfc.tech.Ndef" ],
        [ "android.nfc.tech.MifareClassic" ],
        [ "android.nfc.tech.NfcA" ]
    ]
});

// All tag scans are received by the activity as a new intent. Each
// scan intent needs to be passed to the nfc adapter for processing.
var act = Ti.Android.currentActivity;
act.addEventListener('newintent', function(e) {
    nfcAdapter.onNewIntent(e.intent);
});

// To enable NFC dispatching only while the application is in the foreground,
// the application must signal the module whenever the application state changes.
act.addEventListener('resume', function(e) {
    nfcAdapter.enableForegroundDispatch(dispatchFilter);
});
act.addEventListener('pause', function(e) {
    nfcAdapter.disableForegroundDispatch();
});

Titanium SDK Documentation