The format of APDUs is defined in ISO/IEC 7816-4. A typical SELECT (by AID) command looks like this:
+-----+-----+-----+-----+-----+-------------------------+-----+
| CLA | INS | P1 | P2 | Lc | DATA | Le |
+-----+-----+-----+-----+-----+-------------------------+-----+
| 00 | A4 | 04 | 00 | XX | AID | 00 |
+-----+-----+-----+-----+-----+-------------------------+-----+
You could create it like this:
private byte[] selectApdu(byte[] aid) {
byte[] commandApdu = new byte[6 + aid.length];
commandApdu[0] = (byte)0x00; // CLA
commandApdu[1] = (byte)0xA4; // INS
commandApdu[2] = (byte)0x04; // P1
commandApdu[3] = (byte)0x00; // P2
commandApdu[4] = (byte)(aid.length & 0x0FF); // Lc
System.arraycopy(aid, 0, commandApdu, 5, aid.length);
commandApdu[commandApdu.length - 1] = (byte)0x00; // Le
return commandApdu;
}
You could then send such APDU commands to a tag/HCE device discovered through the reader-mode API:
public abstract void onTagDiscovered(Tag tag) {
IsoDep isoDep = IsoDep.get(tag);
if (isoDep != null) {
try {
isoDep.connect();
byte[] result = isoDep.transceive(selectApdu(SelectAID));
} except (IOException ex) {
} finally {
try {
isoDep.close();
} except (Exception ignored) {}
}
}
}