Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6596041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:01:18+00:00 2026-05-25T18:01:18+00:00

This is my code to read the NFC tag. Why authentication is failing always?

  • 0

This is my code to read the NFC tag. Why authentication is failing always? It is detecting the card but not reading the data. Could you please help me? Why if block is not executing? Where i’am wrong?

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:01:18+00:00Added an answer on May 25, 2026 at 6:01 pm

    Since it is not a new tag, and has been written by another app, I would suspect that the authentication key has changed. You are using the default keys, but the other app may have changed them. The older Nokia phones do this all the time. In that case instead of using MifareClasic.KEY_DEFAULT, you will need to figure out what the new key is for keyA

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I usually do not have difficulty to read JavaScript code but for this one
I am using this code to read input stream but its not working It
I used this code to read file. But fread function always return 0. What
I use this code to read data from sqlite database: keyFromSql = [NSString stringWithCString:(char
I am using this code to read data from a webpage : public class
I want to read a card from Samsung Nexus phone but the android nfc
I used this code to read the data from log files and display in
This code should read from wget2.html and output the links found. But it gives
i write this code to read json data , and there is an error
I am using this code to read data from Oracle Database. That data stored

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.