当前位置: 首页>>代码示例>>Java>>正文


Java NfcAdapter.ACTION_NDEF_DISCOVERED属性代码示例

本文整理汇总了Java中android.nfc.NfcAdapter.ACTION_NDEF_DISCOVERED属性的典型用法代码示例。如果您正苦于以下问题:Java NfcAdapter.ACTION_NDEF_DISCOVERED属性的具体用法?Java NfcAdapter.ACTION_NDEF_DISCOVERED怎么用?Java NfcAdapter.ACTION_NDEF_DISCOVERED使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.nfc.NfcAdapter的用法示例。


在下文中一共展示了NfcAdapter.ACTION_NDEF_DISCOVERED属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: registerTagEvent

@ReactMethod
  private void registerTagEvent(String alertMessage, Boolean invalidateAfterFirstRead, Callback callback) {
      Log.d(LOG_TAG, "registerTag");
isForegroundEnabled = true;

// capture all mime-based dispatch NDEF
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
try {
	ndef.addDataType("*/*");
} catch (MalformedMimeTypeException e) {
	throw new RuntimeException("fail", e);
   }
intentFilters.add(ndef);

// capture all rest NDEF, such as uri-based
      intentFilters.add(new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED));
techLists.add(new String[]{Ndef.class.getName()});

// for those without NDEF, get them as tags
      intentFilters.add(new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED));

if (isResumed) {
	enableDisableForegroundDispatch(true);
}
      callback.invoke();
	}
 
开发者ID:whitedogg13,项目名称:react-native-nfc-manager,代码行数:26,代码来源:NfcManager.java

示例2: handleIntent

public void handleIntent(Intent intent) {
    String action = intent.getAction();
    if (action == null) return;
    Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
    if (tag == null) {
        sendError(TAG_READING_ERROR);
    }else {
        resetTechnologyFlags();
        switch (action) {
            case NfcAdapter.ACTION_NDEF_DISCOVERED:
                setCurrentTag(tag);
                if (!getNdefMaxSize().hasError() && !getTagId().hasError()) {
                    isTagSupported = true;
                    isNdef_Flag = true;
                    displayData();
                    sendNewTagFrame();
                } else {
                    sendError(TAG_READING_ERROR);
                }
                break;
            case NfcAdapter.ACTION_TECH_DISCOVERED:
                setCurrentTag(tag);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) {
                    String[] techList = tag.getTechList();
                    for (String tech : techList) {
                        if (!isTagSupported) {
                            if (Ndef.class.getName().equals(tech)) {
                                DataReply maxSize = getNdefMaxSize();
                                if (!maxSize.hasError() && !getTagId().hasError()) {
                                    isNdef_Flag = false;
                                    isTagSupported = true;
                                    DataReply recordCount = getNdefRecordCount();
                                    if (recordCount.getIntegerData() > 0 && recordCount.getIntegerData() < 256) {
                                        isNdef_Flag = true;
                                        displayData();
                                        sendNewTagFrame();
                                    }else if (recordCount.getIntegerData() == 0){
                                        sendNewEmptyTagFrame();
                                    }else if(recordCount.getError() != 0){
                                        sendError(recordCount.getError());
                                    }
                                } else if (maxSize.hasError()){
                                    sendError(maxSize.getError());
                                }
                            } else if (NdefFormatable.class.getName().equals(tech)) {
                                /*isNdef_Flag = false;
                                isTagSupported = true;
                                if (!getNdefMaxSize().hasError()&& !getTagId().hasError()) {
                                    sendNewEmptyTagFrame();
                                    displayData();
                                } else {
                                    sendError(TAG_READING_ERROR);
                                }*/
                            }
                        } else
                            break;
                    }
                    if (!isTagSupported)
                        sendError(TAG_NOT_SUPPORTED);
                }
                break;
            case NfcAdapter.ACTION_TAG_DISCOVERED:
                setCurrentTag(tag);
                break;
        }
    }
}
 
开发者ID:Dnet3,项目名称:CustomAndroidOneSheeld,代码行数:67,代码来源:NfcShield.java

示例3: initializeNFC

public void initializeNFC() {

        if (nfcInit == false) {
            PackageManager pm = getPackageManager();
            nfcSupported = pm.hasSystemFeature(PackageManager.FEATURE_NFC);

            if (nfcSupported == false) {
                return;
            }

            // when is in foreground
            MLog.d(TAG, "starting NFC");
            mAdapter = NfcAdapter.getDefaultAdapter(this);

            // PedingIntent will be delivered to this activity
            mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

            // Setup an intent filter for all MIME based dispatches
            IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
            try {
                ndef.addDataType("*/*");
            } catch (IntentFilter.MalformedMimeTypeException e) {
                throw new RuntimeException("fail", e);
            }
            mFilters = new IntentFilter[]{ ndef, };

            // Setup a tech list for all NfcF tags
            mTechLists = new String[][]{new String[]{NfcF.class.getName()}};
            nfcInit = true;
        }
    }
 
开发者ID:victordiaz,项目名称:phonk,代码行数:31,代码来源:AppRunnerActivity.java

示例4: onActivityResumed

@Override
public void onActivityResumed(final Activity activity) {
	if (this.connectReceiver == null || (this.getSupportedConnectionMethods() & CONNECTION_METHOD_NFC) == 0)
		return;

	final IntentFilter filter = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
	filter.addDataScheme(NfcYubiKey.YUBIKEY_NEO_NDEF_SCHEME);
	filter.addDataAuthority(NfcYubiKey.YUBIKEY_NEO_NDEF_HOST, null);

	NfcAdapter.getDefaultAdapter(this.activity).enableForegroundDispatch(this.activity,
	                                                                     PendingIntent.getActivity(this.activity, -1, new Intent(this.activity, this.activity.getClass()), 0),
	                                                                     new IntentFilter[]{filter},
	                                                                     null);
	this.isActivityResumed = true;
}
 
开发者ID:pp3345,项目名称:YubiDroid,代码行数:15,代码来源:ConnectionManager.java

示例5: onCreate

@Override
public void onCreate(Bundle savedState) {
    super.onCreate(savedState);

    setContentView(R.layout.foreground_dispatch);
    mText = (TextView) findViewById(R.id.text);
    mText.setText("Scan a tag");

    mAdapter = NfcAdapter.getDefaultAdapter(this);

    // Create a generic PendingIntent that will be deliver to this activity. The NFC stack
    // will fill in the intent with the details of the discovered tag before delivering to
    // this activity.
    mPendingIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    // Setup an intent filter for all MIME based dispatches
    IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    try {
        ndef.addDataType("*/*");
    } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("fail", e);
    }
    mFilters = new IntentFilter[] {
            ndef,
    };

    // Setup a tech list for all NfcF tags
    mTechLists = new String[][] { new String[] { NfcF.class.getName() } };
}
 
开发者ID:appledong,项目名称:AndroidthingsStudy,代码行数:30,代码来源:ForegroundDispatch.java

示例6: createIntentFilter

private IntentFilter createIntentFilter(String mimeType) throws MalformedMimeTypeException {
    IntentFilter intentFilter = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    intentFilter.addDataType(mimeType);
    return intentFilter;
}
 
开发者ID:theGreatWhiteShark,项目名称:mensacard-hack,代码行数:5,代码来源:NfcPlugin.java


注:本文中的android.nfc.NfcAdapter.ACTION_NDEF_DISCOVERED属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。