NFC Tag detected in android shows false

Good Day to everyone.
One problem regarding the above question
What can I do to detect tag without ‘false’?
All other function of the application seems to work just fine

‘Log.d(“YourTag”, “NFC tag detected: ” + tag.toString());’

Following the above log statement, the tag.toString always shows ‘False’

What seems to be the problem??

This is the onNewIntent

  @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        Log.d("YourTag", "onNewIntent called");

        Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        if (tag != null) {
            processNfcTag(tag);
        } else {
            Log.e("YourTag", "Tag detection failed");
        }
    }

and this is the function for processNfcTag

  private void processNfcTag(Tag tag) {
        NFCTagFlow nfctag = new NFCTagFlow(this);
        FileIO fileIO = new FileIO(this); // Instantiate FileIO
        Log.d("YourTag", "Processing NFC tag");

        int sectorOrPage = 4;

        // RequestA Command
        byte[] requestACommand = {(byte) 0x03, (byte) 0x26}; // Request Idle (Wake up one)
        byte[] requestAResponse = nfctag.sendNFCCommand(tag, requestACommand);
        if (requestAResponse[0] == 0x00) {
            byte[] atqResponse = Arrays.copyOfRange(requestAResponse, 1, 3);
            Log.d("YourTag", "RequestA Command successful. ATQ response: " + Arrays.toString(atqResponse));
        } else {
            nfctag.handleCommandError(requestAResponse[0]);
        }

        // Anticoll Command
        byte[] anticollCommand = {(byte) 0x04}; // Anticollision command
        byte[] anticollResponse = nfctag.sendNFCCommand(tag, anticollCommand);
        byte[] uid = null;

        if (anticollResponse[0] == 0x00) {
            boolean multipleCards = anticollResponse[1] == 0x01;
            uid = Arrays.copyOfRange(anticollResponse, 2, 6); // Extracting UID
            String hexUID = nfctag.asciiToHex(new String(uid, StandardCharsets.US_ASCII));
            Log.d("YourTag", "Anticoll Command successful. UID: " + hexUID);
        } else {
            nfctag.handleCommandError(anticollResponse[0]);
        }

        if (uid != null) {
            // Select Command (with UID)
            byte[] selectCommand = new byte[uid.length + 1];
            selectCommand[0] = 0x05; // Select Command
            System.arraycopy(uid, 0, selectCommand, 1, uid.length);
            byte[] selectResponse = nfctag.sendNFCCommand(tag, selectCommand);
            if (selectResponse[0] == 0x00) {
                Log.d("YourTag", "Select Command successful. UID: " + Arrays.toString(uid));
            } else {
                nfctag.handleCommandError(selectResponse[0]);
            }
        } else {
            Log.e("YourTag", "UID is null, Select Command cannot proceed");
        }

        // Inserted Halt Command
        byte[] haltCommand = {(byte) 0x06}; // Halt command
        byte[] haltResponse = nfctag.sendNFCCommand(tag, haltCommand);
        if (haltResponse[0] == 0x00) {
            Log.d("YourTag", "Halt Command successful");
        } else {
            nfctag.handleCommandError(haltResponse[0]);
        }

        // NFC_ActivateCard Command
        byte[] activateCardCommand = new byte[]{/* Construct according to your parameters */};
        byte[] activateCardResponse = nfctag.sendNFCCommand(tag, activateCardCommand);
        if (activateCardResponse[0] == 0x00) {
            Log.d("YourTag", "NFC_ActivateCard Command successful");
        } else {
            nfctag.handleCommandError(activateCardResponse[0]);
        }

        // NFC_Exchange Command
        byte[] dataToSend = {/* Your data here */};
        byte[] exchangeCommand = new byte[dataToSend.length + 2];
        exchangeCommand[0] = (byte) 0xB5; // Exchange command code
        exchangeCommand[1] = (byte) dataToSend.length;
        System.arraycopy(dataToSend, 0, exchangeCommand, 2, dataToSend.length);
        byte[] exchangeResponse = nfctag.sendNFCCommand(tag, exchangeCommand);
        if (exchangeResponse[0] == 0x00) {
            Log.d("YourTag", "NFC_Exchange Command successful. Data received: " + Arrays.toString(exchangeResponse));
        } else {
            nfctag.handleCommandError(exchangeResponse[0]);
        }

        // Send file to NFC tag
        new Thread(() -> {
            boolean sendResult = nfctag.sendFileToTag(tag, sectorOrPage);
            if (sendResult) {
                Log.d("YourTag", "File sent to tag successfully.");
            } else {
                Log.e("YourTag", "Failed to send file to tag.");
            }
        }).start();

        // Handling NdefMessage if needed
        final Ndef ndef = Ndef.get(tag);
        final NdefMessage[] ndefMessage = {null};
        if (ndef != null) {
            try {
                ndef.connect();
                ndefMessage[0] = ndef.getNdefMessage();
                ndef.close();
            } catch (IOException | FormatException e) {
                e.printStackTrace();
            }
        }

        if (ndefMessage[0] != null) {
            new Thread(() -> {
                File directory = fileIO.createFile(MainActivity.this);
                if (directory != null) {
                    fileIO.writeDataToFile(directory, ndefMessage[0]);
                    runOnUiThread(() -> {
                        textView3.setText("NFC Message Written to File");
                    });
                } else {
                    Log.e("FileIO", "Directory is null, cannot write to file.");
                }
            }).start();
        } else {
            Log.e("YourTag", "NdefMessage is null");
        }
    }
}

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật