android: resource = "@ xml / filter_nfc"
/>
<-! Capture anything using NfcF ->android.nfc.tech.NfcA android.nfc.tech.MifareClassic android.nfc.tech.MifareUltralight
isNFC = getPackageManager () hasSystemFeature (PackageManager.FEATURE_NFC);.
if (isNFC) {
mAdapter = NfcAdapter.getDefaultAdapter (this);
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_TECH_DISCOVERED);
ndef.addAction (NfcAdapter.ACTION_TAG_DISCOVERED);
try {
ndef.addDataType ("* / *");
} Catch (MalformedMimeTypeException e) {
Log.e ("NFCfail", "runtime Exception");
}
mFilters = new IntentFilter [] {ndef};
/ / Setup a tech list for all MifareClassic tags
mTechLists = new String [] [] {
new String [] {MifareClassic.class.getName ()},
new String [] {NfcA.class.getName ()}};
}
protected void onResume () {
super.onResume ();
if (isNFC && mAdapter.isEnabled ()) {
mAdapter.enableForegroundDispatch (this, mPendingIntent, mFilters,
mTechLists);
}
}
After induction card to get to the data in onNewIntent follows:
public void onNewIntent (Intent intent) {
String action = intent.getAction ();
/ / Action printout is: android.nfc.action.TECH_DISCOVERED
Tag tagFromIntent = intent.getParcelableExtra (NfcAdapter.EXTRA_TAG);
/ / TagFromIntent printout is: TAG: Tech [android.nfc.tech.NfcA]
The question is:
MifareClassic mfc = MifareClassic.get (tagFromIntent);
/ / Here mfc print output is null This is why
}
Thank you!
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Seeking answers ah ah ah

No comments:
Post a Comment