0

I just want that activity should not reopen on each scan, it will stay in the application and when the card is scanned it will simply update the NFC card id in any text view or toast....please help me, i am stuck

Main activity:

public class MainActivity extends AppCompatActivity {

private NfcAdapter nfcAdapter;
private String baseUrl = "/api/auth/login";


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
     getRFID();

}

   private void getRFID() {


    Intent intent = getIntent();
    String action = intent.getAction();


    if (nfcAdapter.ACTION_TAG_DISCOVERED.equals(action)) {
        Toast.makeText(this,
                "Card Found",
                Toast.LENGTH_SHORT).show();
        Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);

        if (tag == null) {
            // startActivity(new Intent(Login.this, HomeFragment.class));
        } else {
            String tagInfo = "";
            byte[] tagId = tag.getId();
            for (int i = 0; i < tagId.length; i++) {
                tagInfo += Integer.toHexString(tagId[i] & 0xFF) + "";
            }
            Toast.makeText(this, " " + tagInfo.toString(), Toast.LENGTH_SHORT).show();
            // etEmail.setText(tagInfo.toString());
        }
    } else {
        //  startActivity(new Intent(Login.this , MainActivity.class));
        // finish();
    }


    //  startActivity(new Intent(Login.this, MainActivity.class));


}

}

Manifest:

    <activity android:name=".MainActivity">
    <intent-filter>
        <action android:name="android.nfc.action.TAG_DISCOVERED" />
        <category android:name="android.intent.category.DEFAULT" />

    </intent-filter>


    </activity>
  • I’m voting to close this question because duplicate of https://stackoverflow.com/q/71223794/2373819 – Andrew Mar 08 '22 at 16:16
  • @Andrew You can use the "duplicate" close reason for these, which will create a link between the two questions. – Ryan M Mar 10 '22 at 01:49
  • @Ryan M no I cannot use "duplicate" close as the answer I linked is not accepted or up voted as the new user probably has not got the hang of stack overflow yet. This is even though it is the same answer I would give – Andrew Mar 10 '22 at 09:17
  • @Andrew Oh whoops, my mistake. You're correct. – Ryan M Mar 10 '22 at 09:20

0 Answers0