# Modules.Nfc.NfcForegroundDispatchFilter
A filter specifying intent, intent filters and technology lists used to match dispatch intents.
# Overview
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 (opens new window)
# 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();
});
# Properties
# apiName READONLY
The name of the API that this proxy corresponds to.
The value of this property is the fully qualified name of the API. For example, Titanium.UI.Button
returns Ti.UI.Button
.
# 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
The intent filters to override dispatching for, or null to always dispatch.
# lifecycleContainer
The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.
If this property is set to a Window or TabGroup, then the corresponding Activity lifecycle event callbacks will also be called on the proxy. Proxies that require the activity lifecycle will need this property set to the appropriate containing Window or TabGroup.
# techLists
The tech lists used to perform matching for dispatching the ACTION_TECH_DISCOVERED intent.