當前位置: 首頁>>代碼示例>>Java>>正文


Java NfcAdapter.enableForegroundDispatch方法代碼示例

本文整理匯總了Java中android.nfc.NfcAdapter.enableForegroundDispatch方法的典型用法代碼示例。如果您正苦於以下問題:Java NfcAdapter.enableForegroundDispatch方法的具體用法?Java NfcAdapter.enableForegroundDispatch怎麽用?Java NfcAdapter.enableForegroundDispatch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.nfc.NfcAdapter的用法示例。


在下文中一共展示了NfcAdapter.enableForegroundDispatch方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: enableDisableForegroundDispatch

import android.nfc.NfcAdapter; //導入方法依賴的package包/類
private void enableDisableForegroundDispatch(boolean enable) {
    Log.i(LOG_TAG, "enableForegroundDispatch, enable = " + enable);
    NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(context);
    Activity currentActivity = getCurrentActivity();

    if (nfcAdapter != null && !currentActivity.isFinishing()) {
        try {
if (enable) {
                nfcAdapter.enableForegroundDispatch(currentActivity, getPendingIntent(), getIntentFilters(), getTechLists());
} else {
	nfcAdapter.disableForegroundDispatch(currentActivity);
}
        } catch (IllegalStateException e) {
            Log.w(LOG_TAG, "Illegal State Exception starting NFC. Assuming application is terminating.");
        }
    }
}
 
開發者ID:whitedogg13,項目名稱:react-native-nfc-manager,代碼行數:18,代碼來源:NfcManager.java

示例2: setupForegroundDispatch

import android.nfc.NfcAdapter; //導入方法依賴的package包/類
public void setupForegroundDispatch() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) {
        NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(activity);
        final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
        final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);

        String[][] techList = new String[3][1];
        techList[0][0] = "android.nfc.tech.NdefFormatable";
        techList[1][0] = "android.nfc.tech.NfcA";
        techList[2][0] = "android.nfc.tech.Ndef";

        IntentFilter[] filters = new IntentFilter[2];
        filters[0] = new IntentFilter();
        filters[0].addAction(NfcAdapter.ACTION_TECH_DISCOVERED);
        filters[0].addCategory(Intent.CATEGORY_DEFAULT);
        filters[1] = new IntentFilter();
        filters[1].addAction(NfcAdapter.ACTION_TAG_DISCOVERED);
        filters[1].addCategory(Intent.CATEGORY_DEFAULT);
        if (nfcAdapter != null) {
            if (!isForeground) {
                nfcAdapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
                isForeground = true;
            }
        }
    }
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:27,代碼來源:NfcShield.java

示例3: setupForegroundDispatch

import android.nfc.NfcAdapter; //導入方法依賴的package包/類
/**
 * Setup the recognition of nfc tags when the activity is opened (foreground)
 *
 * @param activity The corresponding {@link Activity} requesting the foreground dispatch.
 * @param adapter The {@link NfcAdapter} used for the foreground dispatch.
 */
public static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) {
    final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);

    IntentFilter[] filters = new IntentFilter[1];
    String[][] techList = new String[][]{};

    // Filter for nfc tag discovery
    filters[0] = new IntentFilter();
    filters[0].addAction(NfcAdapter.ACTION_TAG_DISCOVERED);
    filters[0].addCategory(Intent.CATEGORY_DEFAULT);

    adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
}
 
開發者ID:digital-voting-pass,項目名稱:polling-station-app,代碼行數:23,代碼來源:PassportConActivity.java

示例4: setupForegroundDispatch

import android.nfc.NfcAdapter; //導入方法依賴的package包/類
private static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter)
{
    final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());

    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);

    IntentFilter[] filters = new IntentFilter[1];
    String[][] techList = new String[][]{};

    filters[0] = new IntentFilter();
    filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
    filters[0].addCategory(Intent.CATEGORY_DEFAULT);

    try
    {
        /* Mime type for BT pairing */
        filters[0].addDataType("application/vnd.bluetooth.ep.oob");
    }
    catch (IntentFilter.MalformedMimeTypeException e)
    {
        throw new RuntimeException("Unsupported mime type!");
    }

    /* Start Foreground dispatcher */
    adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
}
 
開發者ID:AinaWireless,項目名稱:PairingExample,代碼行數:29,代碼來源:MainActivity.java


注:本文中的android.nfc.NfcAdapter.enableForegroundDispatch方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。