Это мой код для чтения тега NFC.Почему аутентификация всегда терпит неудачу?Это обнаружение карты, но не чтение данных.Не могли бы вы мне помочь?Почему, если блок не выполняется?Где я не прав?
void resolveIntent(Intent intent)
{
String action = intent.getAction();
if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action))
{
Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
MifareClassic mfc = MifareClassic.get(tagFromIntent);
byte[] data;
try
{
mfc.connect();
boolean auth = false;
String cardData = "";
int sectorCount = mfc.getSectorCount();
int blockCount = 0;
int blockIndex = 0;
for(int j = 0; j < sectorCount; j++)
{
auth = mfc.authenticateSectorWithKeyA(j, MifareClassic.KEY_DEFAULT);
if(auth)
{
blockCount = mfc.getBlockCountInSector(j);
blockIndex = 0;
for(int i = 0; i < blockCount; i++)
{
blockIndex = mfc.sectorToBlock(j);
data = mfc.readBlock(blockIndex);
cardData = cardData + getHexString(data, data.length);
blockIndex++;
}
}
else
{
// Authentication failed - Handle it
showAlert(AUTH); //this alert message is executing always
}
}
Toast.makeText(getApplicationContext(), cardData, Toast.LENGTH_LONG).show();
}
catch (IOException e)
{
Log.e(TAG, e.getLocalizedMessage());
showAlert(NETWORK);
}
}//end of if
}// End of method