我使用下面的代码,但它总是崩溃。我想要文本视图数据中的 UID。谁能帮我?我使用来自 asc 的库
reader.setOnStateChangeListener(new Reader.OnStateChangeListener() {
@Override
public void onStateChange(int slotNum, int prevState, int currState) {
//De APDU command om de UID uit te lezen
byte[] command = {(byte)0xFF, (byte)0xCA, (byte)0x00, (byte)0x00, (byte)0x00};
final byte[] response = new byte[256];
if(currState == Reader.CARD_PRESENT) {
try {
reader.power(slotNum, Reader.CARD_WARM_RESET);
reader.setProtocol(slotNum, Reader.PROTOCOL_T0 | Reader.PROTOCOL_T1);
reader.transmit(slotNum, command, command.length, response, response.length);
runOnUiThread(new Runnable() {
@Override
public void run() {
TextView data = (TextView) findViewById(R.id.LidkaartID_detail);
//data.append(Arrays.toString(response));
Toast.makeText(MainActivity.this, Arrays.toString(response), Toast.LENGTH_LONG).show();
}
});
} catch (ReaderException e) {
e.printStackTrace();
}
}
}
});
这可能是因为您尝试从后台线程更新 UI。使用这个 :
runOnUiThread(new Runnable() {
@Override
public void run() {
textView.append(text);
}
});