only capture tag by reader mode if possible
This commit is contained in:
@@ -184,13 +184,14 @@ public class MainActivity extends Activity implements NfcAdapter.ReaderCallback
|
||||
}
|
||||
|
||||
private void enableReaderMode() {
|
||||
//mNfcAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters, mTechLists);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(NfcAdapter.EXTRA_READER_PRESENCE_CHECK_DELAY, 2000);
|
||||
NfcAdapter.getDefaultAdapter(this).enableReaderMode(this, this,
|
||||
NfcAdapter.FLAG_READER_NFC_A | NfcAdapter.FLAG_READER_NFC_B | NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK,
|
||||
bundle);
|
||||
} else {
|
||||
//NfcAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters, mTechLists);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,7 +322,6 @@ public class MainActivity extends Activity implements NfcAdapter.ReaderCallback
|
||||
if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(intent.getAction())) {
|
||||
NFCReader nfcReader = NFCReader.get(intent);
|
||||
if (nfcReader != null) {
|
||||
textViewVPCDStatus.append(getResources().getString(R.string.status_tag_discovered)+"\n");
|
||||
forceConnect(nfcReader);
|
||||
} else {
|
||||
super.onNewIntent(intent);
|
||||
|
||||
@@ -44,7 +44,7 @@ public class NFCReader implements SCReader {
|
||||
card.close();
|
||||
}
|
||||
|
||||
private static int TIMEOUT = 10000;
|
||||
private static int TIMEOUT = 2500;
|
||||
@Override
|
||||
public void powerOn() {
|
||||
/* should already be connected... */
|
||||
@@ -105,7 +105,16 @@ public class NFCReader implements SCReader {
|
||||
if (intent.getExtras() != null) {
|
||||
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
|
||||
if (tag != null) {
|
||||
nfcReader = NFCReader.get(tag);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
/* Disconnect from the tag here. The reader mode will capture the tag again */
|
||||
try {
|
||||
IsoDep.get(tag).close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
nfcReader = NFCReader.get(tag);
|
||||
}
|
||||
intent.removeExtra(NfcAdapter.EXTRA_TAG);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user