-
Notifications
You must be signed in to change notification settings - Fork 17
Working with card readers (smart‐card‐reader‐lib)
Kristel Merilain edited this page Jun 28, 2021
·
3 revisions
High level API for communicating with supported smart card readers in Android.
Currently supported smart card readers:
- ACR38U PocketMate Smart Card Reader
- ACR39U PocketMate II Smart Card Reader
- SCR3500 B Smart Card Reader
- SCR3500 C Smart Card Reader
Context context = ...;
UsbManager usbManager = ...;
ImmutableList<SmartCardReader> readers = ImmutableList.of(
new AcsSmartCardReader(usbManager),
new IdentivSmartCardReader(context, usbManager));
SmartCardReaderManager smartCardReaderManager =
new SmartCardReaderManager(context, usbManager, readers);
// get the status of the smart card
// prompts the user for permissions and tries to connect to the card reader
// when reader is connected, tries to connect to the card in the reader
smartCardReaderManager.status()
.doOnNext(status -> {
switch (status) {
case IDLE:
// no reader found
break;
case READER_DETECTED:
// reader found, user should insert card into the reader
break;
case CARD_DETECTED:
// card found in the reader, ready to communicate with the card
break;
}
});
// check whether the device is supported by readers in the manager
UsbDevice usbDevice = ...;
boolean supports = smartCardReaderManager.supports(usbDevice);
SmartCardReaderManager smartCardReaderManager = null;
Observable<Optional<PersonalData>> personalDataObservable = smartCardReaderManager.status()
.observeOn(Schedulers.io())
.map(status -> {
if (status.equals(SmartCardReaderStatus.CARD_DETECTED)) {
return Optional.fromNullable(smartCardReaderManager.connectedReader());
} else {
return Optional.<SmartCardReader>absent();
}
})
.map(smartCardReader -> {
if (smartCardReader.isPresent()) {
return Optional.of(Token.create(smartCardReader.get()));
} else {
return Optional.<Token>absent();
}
})
.map(token -> {
if (token.isPresent()) {
return Optional.of(token.get().personalData());
} else {
return Optional.absent();
}
});
Disposable personalDataDisposable = personalDataObservable
.observeOn(AndroidSchedulers.mainThread())
.subscribe(personalData -> {
if (personalData.isPresent()) {
// show personal data
} else {
// show info how to connect reader and card
}
});