|
|
(3 intermediate revisions by 2 users not shown) |
Line 1: |
Line 1: |
| * Get RFCardReaderDevice
| | {{Migrating|https://smartpossdk.gitbook.io/cloudpossdk/faq/card/use-mifare-card}} |
| <syntaxhighlight lang="java" line='line'>
| |
| device = (RFCardReaderDevice) POSTerminal.getInstance(mContext).getDevice(POSTerminal.DEVICE_NAME_RF_CARD_READER);
| |
| </syntaxhighlight>
| |
| * Open device
| |
| <syntaxhighlight lang="java" line='line'>
| |
| device.open();
| |
| </syntaxhighlight>
| |
| * Search Card
| |
| <syntaxhighlight lang="java" line='line'>
| |
| OperationListener listener = new OperationListener() {
| |
| @Override
| |
| public void handleResult(OperationResult arg0) {
| |
| if (arg0.getResultCode() == OperationResult.SUCCESS) {
| |
| sendSuccessLog2(mContext.getString(R.string.find_card_succeed));
| |
| rfCard = ((RFCardReaderOperationResult) arg0).getCard();
| |
| } else {
| |
| sendFailedLog2(mContext.getString(R.string.find_card_failed));
| |
| }
| |
| }
| |
| };
| |
| device.listenForCardPresent(listener, TimeConstants.FOREVER); The result will be returned in the callback listener.
| |
| </syntaxhighlight>
| |
| * Read
| |
| <syntaxhighlight lang="java" line='line'>
| |
| // demo for sector 1, block 2
| |
| int sectorIndex=1;
| |
| int blockIndex =2;
| |
| if (rfCard instanceof MifareCard) {
| |
| byte[] key = new byte[]{
| |
| (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
| |
| (byte) 0xFF
| |
| };
| |
| try {
| |
| MifareCard card = ((MifareCard) rfCard);
| |
| boolean verifyResult = card.verifyKeyA(sectorIndex, key);
| |
| if(verifyResult){
| |
| byte[] result = card.readBlock(sectorIndex, blockIndex);
| |
| }
| |
| } catch (DeviceException e) {
| |
| e.printStackTrace();
| |
| }
| |
| }
| |
| </syntaxhighlight>
| |
| * write
| |
| <syntaxhighlight lang="java" line='line'>
| |
| // demo for sector 1, block 2
| |
| int sectorIndex=1;
| |
| int blockIndex =2;
| |
| if (rfCard instanceof MifareCard) {
| |
| byte[] key = new byte[]{
| |
| (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
| |
| (byte) 0xFF
| |
| };
| |
| try {
| |
| MifareCard card = ((MifareCard) rfCard);
| |
| boolean verifyResult = card.verifyKeyB(sectorIndex, key);
| |
| if(verifyResult ){
| |
| card.writeBlock(sectorIndex, blockIndex, arryData);
| |
| }
| |
| } catch (DeviceException e) {
| |
| e.printStackTrace();
| |
| }
| |
| }
| |
| </syntaxhighlight>
| |
| * Close device
| |
| <syntaxhighlight lang="java" line='line'>
| |
| device.close();
| |
| </syntaxhighlight>
| |