Skip to content

Added a feature of Reading the ID of the NFC Card only with param of "id" #693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions app/src/main/java/com/termux/api/apis/NfcAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.termux.api.util.ResultReturner;
import com.termux.shared.logger.Logger;

import java.nio.charset.StandardCharsets;

public class NfcAPI {

private static final String LOG_TAG = "NfcAPI";
Expand Down Expand Up @@ -165,6 +167,9 @@ public void writeJson(JsonWriter out) throws Exception {
case "full":
readFullNDEFTag(intent,out);
break;
case "id":
readNDEFID(intent,out);
break;
case "noData":
readNDEFTag(intent,out);
break;
Expand Down Expand Up @@ -245,6 +250,18 @@ public void readNDEFTag(Intent intent, JsonWriter out) throws Exception {
}
}

public void readNDEFID(Intent intent, JsonWriter out) throws Exception {
NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
byte[] tag_id = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID);
out.beginObject();
StringBuilder sb = new StringBuilder();
for (byte b : tag_id) {
sb.append(String.format("%02X", b));
}
out.name("card_id").value(sb.toString());
out.endObject();
}

public void readFullNDEFTag(Intent intent, JsonWriter out) throws Exception {
Logger.logVerbose(LOG_TAG, "readFullNDEFTag");

Expand Down