語言

NfcAdapter.EnableForegroundDispatch 方法

定義

啟用對特定活動的前景派遣。

[Android.Runtime.Register("enableForegroundDispatch", "(Landroid/app/Activity;Landroid/app/PendingIntent;[Landroid/content/IntentFilter;[[Ljava/lang/String;)V", "")]
public void EnableForegroundDispatch(Android.App.Activity? activity, Android.App.PendingIntent? intent, Android.Content.IntentFilter[]? filters, string[][]? techLists);
[<Android.Runtime.Register("enableForegroundDispatch", "(Landroid/app/Activity;Landroid/app/PendingIntent;[Landroid/content/IntentFilter;[[Ljava/lang/String;)V", "")>]
member this.EnableForegroundDispatch : Android.App.Activity * Android.App.PendingIntent * Android.Content.IntentFilter[] * string[][] -> unit

參數

activity
Activity

要派遣的活動

intent
PendingIntent

PendingIntent 開始發送

filters
IntentFilter[]

IntentFilters 用來覆寫派遣,或用 null 來永遠派遣

techLists
String[][]

用於調度 NfcAdapter#ACTION_TECH_DISCOVERED 意圖的技術清單

屬性

例外狀況

如果活動目前不在前景

備註

啟用對特定活動的前景派遣。

這會在派遣發現者 Tag 到應用程式時優先給前景活動。

若此方法提供任何意圖過濾器,則用於匹配 與 NfcAdapter#ACTION_TAG_DISCOVERED的調度意圖NfcAdapter#ACTION_NDEF_DISCOVERED。 由於 NfcAdapter#ACTION_TECH_DISCOVERED 依賴 IntentFilter 以外的元資料來匹配該派遣,Intent 是透過分別傳遞技術清單來處理。 科技列表中的每個第一級項目代表一組必須齊備的科技。 若第一層組中任一符合,則派遣會經過給定的 PendingIntent。 換句話說,第二層是一起AND的,第一層的項目則是一起OR的。

如果你同時通過 null 和 filterstechLists 參數,那就成了萬用牌,會讓前景活動透過意圖接收所有標籤 NfcAdapter#ACTION_TAG_DISCOVERED 。

此方法必須從主執行緒呼叫,且僅在活動處於前景(恢復)時。 此外,活動必須在回調完成Activity#onPause前呼叫#disableForegroundDispatch,以停用啟用前台派遣。

需要 android.Manifest.permission#NFC 權限。

Java 文件 android.nfc.NfcAdapter.enableForegroundDispatch(android.app.Activity, android.app.PendingIntent, android.content.IntentFilter[], java.lang.String[][])。

本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。

適用於