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

  • SEARCH
  • Home
  • 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 9151713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:52:10+00:00 2026-06-17T11:52:10+00:00

I’ve an app that scans NFC tags to get information from the payload and

  • 0

I’ve an app that scans NFC tags to get information from the payload and then sends that info to a server via web service. It works fine. The tags are Mifare. The mobile part of the system before i joined the company was written in J2me for nokia c700. I’ve re-written the system in Android. The Android app can get the tag ID and read the payload. If there is no payload then it just reads the tag ID, which is fine.

The problem is when i scan a tag that has not been formatted then i can’t get the tagID. The old system on the nokias could read a tagID from an unformatted tag. How can i do this in Android? Why does the tag have to be formatted?

Thanks in advance.

[edit]

if( intentAction.equalsIgnoreCase(NFC_ACTION)){

             nfcScanTimeFromDB = null;

            cursor = nfcscannerapplication.loginValidate.getLastTagFromTransations();

            if (cursor.getCount() > 0) {
                if (cursor.moveToLast()) {

                    _tagScanTime = cursor.getLong(cursor
                            .getColumnIndex(LoginValidate.C_TAG_SCAN_TIME));

                    nfcScanTimeFromDB = new DateTime(_tagScanTime);

                }
            }

            if(cursor.getCount() == 0){
                //DB must be empty
                Log.e(TAG, "just scanned an nfc tag and DB must be empty");
                Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);

                tagId = bytesToHexString(tag.getId());
                Log.e(TAG, "tagId immediately after scanning nfc tag = " + tagId);

                if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {

                    Log.e(TAG, "NFC Tag scanned");

                    // get the messages from the intent
                    Parcelable[] rawMsgs = intent
                            .getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
                    if (rawMsgs != null) {
                        msgs = new NdefMessage[rawMsgs.length];
                        for (int i = 0; i < rawMsgs.length; i++) {
                            msgs[i] = (NdefMessage) rawMsgs[i];
                        }
                    }
                } else {
                    Log.e(TAG, "ndef not discovered!!!!!!");
                }

                 Cursor c = nfcscannerapplication.loginValidate.queryAllFromCarer();

                  if(c.getCount() == 0){

                      Toast.makeText(this, "Please login before signing in",
                                Toast.LENGTH_LONG).show();
                      Intent intent = new Intent(NfcscannerActivity.this, EntryActivity.class);
                      startActivity(intent);
                  }else{
                      c.moveToLast();
                      tagPerson = c.getString(c.getColumnIndex(LoginValidate.C_CARER_ID));
                  }




                // process the msgs array
                for (int i = 0; i < msgs.length; i++) {

                    NdefRecord[] records = msgs[i].getRecords();
                    Log.e(TAG, "ndefrecord has a length of " + records.length);

                    tr = parse(records[i]);
                    payload = tr.getText();

                    Log.e(TAG, "TextRecord.text = " + tr.getText());


                }

                if(payload.length() == 0){

                    tagType = "1";
                    tagCompany = c.getString(c.getColumnIndex(LoginValidate.C_COMP_ID));
                    tagPerson = tagId;//c.getString(c.getColumnIndex(LoginValidate.C_CARER_ID));
                    tagUserName = tagId;
                    tagLatitude = "0.0000000";
                    tagLongitude = "0.0000000"; 

                    if(rotasOnly.trim().equalsIgnoreCase("false")){
                         processinfo();
                    }
                }else{

                // /////////////////////////////////////////////////// split the payload
                // using delimiter. assign value at position[0] to tagType
                String[] splitPayload = payload.split(",");



                tagType = splitPayload[0];
                //tagCompany = splitPayload[1];


                c.moveToLast();
                tagCompany = c.getString(c.getColumnIndex(LoginValidate.C_COMP_ID));


                if(splitPayload[2].length() == 0 || splitPayload[2] == null || splitPayload[2].trim().equalsIgnoreCase("0")){

                    tagPerson = c.getString(c.getColumnIndex(LoginValidate.C_CARER_ID));

                }else{

                tagPerson = splitPayload[2];

                }

                tagUserName = splitPayload[3];
                tagLatitude = "0.0000000";
                tagLongitude = "0.0000000"; 

                if(rotasOnly.trim().equalsIgnoreCase("false")){
                     processinfo();

                }else{
                    Log.e(TAG, "cant process tag because of company option 160 rotas only");
                }

                }   

            }else{



            //DB not empty///////////////////

            DateTime nfcScanTimeMinustagTouchInterval = new DateTime();
            nfcScanTimeMinustagTouchInterval.minusMinutes(Integer.parseInt(tagTouchInterval));





//          AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
//          // For example to set the volume of played media to maximum.
//          audioManager.setStreamVolume (AudioManager.STREAM_MUSIC, 
//                        audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC),0);
//          MediaPlayer mediaPlayer = MediaPlayer.create(this, R.raw.meep2); 
//          mediaPlayer.start();
            //mediaPlayer.release();
            //mediaPlayer = null; 


        Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);

        tagId = bytesToHexString(tag.getId());
        Log.e(TAG, "tagId immediately after scanning nfc tag = " + tagId);

        if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {

            Log.e(TAG, "NFC Tag scanned");

            // get the messages from the intent
            Parcelable[] rawMsgs = intent
                    .getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
            if (rawMsgs != null) {
                msgs = new NdefMessage[rawMsgs.length];
                for (int i = 0; i < rawMsgs.length; i++) {
                    msgs[i] = (NdefMessage) rawMsgs[i];
                }
            }
        } else {
            Log.e(TAG, "ndef not discovered!!!!!!");
        }

         Cursor c = nfcscannerapplication.loginValidate.queryAllFromCarer();

          if(c.getCount() == 0){

              Toast.makeText(this, "Please login before signing in",
                        Toast.LENGTH_LONG).show();
              Intent intent = new Intent(NfcscannerActivity.this, EntryActivity.class);
              startActivity(intent);
          }else{
              c.moveToLast();
              tagPerson = c.getString(c.getColumnIndex(LoginValidate.C_CARER_ID));
          }




        // process the msgs array
        for (int i = 0; i < msgs.length; i++) {

            NdefRecord[] records = msgs[i].getRecords();
            Log.e(TAG, "ndefrecord has a length of " + records.length);

            tr = parse(records[i]);
            payload = tr.getText();

            Log.e(TAG, "TextRecord.text = " + tr.getText());
            Log.e(TAG, "payload len = " + payload.length() + " so must be a blank formatted tag!");


        }

        if(payload.length() == 0){

            tagType = "1";
            tagCompany = c.getString(c.getColumnIndex(LoginValidate.C_COMP_ID));
            tagPerson = tagId;//c.getString(c.getColumnIndex(LoginValidate.C_CARER_ID));
            tagUserName = tagId;
            tagLatitude = "0.0000000";
            tagLongitude = "0.0000000"; 

            if(rotasOnly.trim().equalsIgnoreCase("false")){
                 processinfo();
            }
        }else{


        // /////////////////////////////////////////////////// split the payload
        // using delimiter. assign value at position[0] to tagType
        String[] splitPayload = payload.split(",");



        tagType = splitPayload[0];
        //tagCompany = splitPayload[1];
        tagCompany = c.getString(c.getColumnIndex(LoginValidate.C_COMP_ID));

        if(splitPayload[2].length() == 0 || splitPayload[2] == null || splitPayload[2].trim().equalsIgnoreCase("0")){

            tagPerson = c.getString(c.getColumnIndex(LoginValidate.C_CARER_ID));

        }else{

        tagPerson = splitPayload[2];

        }

        tagUserName = splitPayload[3];
        tagLatitude = "0.0000000";
        tagLongitude = "0.0000000"; 

        if(rotasOnly.trim().equalsIgnoreCase("false")){
             processinfo();
        }else{
            Log.e(TAG, "cant process tag because of company option 160 rotas only");
        }


        }   

            }//finished processing tag with a NONE empty DB




        }

[edit2]

if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(getIntent().getAction())) {
                  Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
                  byte[] tagIdbyteArray = tag.getId();
                  Log.e(TAG, "unformatted tag found with a tagID of " + tagIdbyteArray);
                }

[edit3]

<activity
            android:name=".NfcscannerActivity"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.nfc.action.NDEF_DISCOVERED" />

                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="text/plain" />
            </intent-filter>
            <intent-filter>
                <action android:name="com.carefreegroup.QRCODE_ACTION" />

                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="text/plain" />
            </intent-filter>

            <intent-filter>
            <action android:name="android.nfc.action.TECH_DISCOVERED"/>
            </intent-filter> 

            <meta-data android:name="android.nfc.action.TECH_DISCOVERED"
                       android:resource="@xml/nfc_tech_filter" />

        </activity>

.

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
  <tech-list>
      <tech>android.nfc.tech.IsoDep</tech>
        <tech>android.nfc.tech.NfcA</tech>
        <tech>android.nfc.tech.NfcB</tech>
        <tech>android.nfc.tech.NfcF</tech>
        <tech>android.nfc.tech.NfcV</tech>
        <tech>android.nfc.tech.Ndef</tech>
        <tech>android.nfc.tech.NdefFormatable</tech>
    <tech>android.nfc.tech.MifareClassic</tech>
    <tech>android.nfc.tech.MifareUltralight</tech>
  </tech-list>
</resources>

.

if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(getIntent().getAction())) {
                  Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
                  byte[] tagIdbyteArray = tag.getId();
                  Log.e(TAG, "unformatted tag found with a tagID of " + tagIdbyteArray);
                }

[edit 4]

01-21 09:27:35.180: D/NativeNfcTag(512): Connect Failed - status = 146
01-21 09:27:35.180: E/NFC JNI(512): doDisconnect() - Target already disconnected

[edit5]

01-21 10:07:25.420: E/NfcService(512): No tag fallback activity found for Intent { act=android.nfc.action.TAG_DISCOVERED (has extras) }

[edit6]

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
  <tech-list>

    <tech>android.nfc.tech.MifareUltralight</tech>
  </tech-list>
</resources>
  • 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-06-17T11:52:11+00:00Added an answer on June 17, 2026 at 11:52 am

    If the MIFARE Classic tags are not formatted to contain NDEF, you can receive an intent for them (and get the ID) as follows (from the documentation):

    Add to you manifest for the activity that needs to receive the intents:

    <activity>
      ...
      <intent-filter>
        <action android:name="android.nfc.action.TECH_DISCOVERED"/>
        <category android:name="android.intent.category.DEFAULT" />
      </intent-filter>
    
      <meta-data android:name="android.nfc.action.TECH_DISCOVERED"
        android:resource="@xml/nfc_tech_filter" />
      ...
    </activity>
    

    Create a new file <project-root>/res/xml/nfc_tech_filter.xml containing:

    <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
      <tech-list>
        <tech>android.nfc.tech.MifareClassic</tech>
      </tech-list>
      <tech-list>
        <tech>android.nfc.tech.MifareUltralight</tech>
      </tech-list>
    </resources>
    

    In your activity, at some suiutable place, add:

    if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(getIntent().getAction())) {
      Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
      byte[] tagId = tag.getId();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a view passing on information from a database: def serve_article(request, id): served_article
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Basically, what I'm trying to create is a page of div tags, each has

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.