当前位置: 首页>>代码示例>>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;未经允许,请勿转载。