本文整理匯總了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();
}
示例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;
}
}
}
示例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;
}
}
示例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;
}
示例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() } };
}
示例6: createIntentFilter
private IntentFilter createIntentFilter(String mimeType) throws MalformedMimeTypeException {
IntentFilter intentFilter = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
intentFilter.addDataType(mimeType);
return intentFilter;
}