https://github.com/springcard/android-keyple
Keyple Plugin SpringCard Android PC/SC Like
https://github.com/springcard/android-keyple
Last synced: 5 months ago
JSON representation
Keyple Plugin SpringCard Android PC/SC Like
- Host: GitHub
- URL: https://github.com/springcard/android-keyple
- Owner: springcard
- License: other
- Created: 2022-03-07T16:20:23.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-06-05T07:38:43.000Z (about 2 years ago)
- Last Synced: 2024-06-05T10:17:55.366Z (about 2 years ago)
- Language: Kotlin
- Size: 459 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Keyple Plugin SpringCard PC/SC-like Android
[](http://kotlinlang.org)
[](https://springcard.github.io/android-keyple/)
## Overview
The **Keyple Plugin SpringCard PC/SC-like Android** is an add-on to allow an application using Keyple to interact with [SpringCard](https://www.springcard.com) PC/SC readers in Android.
The physical link can be either USB or Bluetooth Low Energy.
## Setup
Here are the necessary dependencies to declare in your project to integrate this library:
### Gradle Groovy
```groovy
implementation 'org.calypsonet.terminal:calypsonet-terminal-reader-java-api:1.0.+'
implementation 'org.eclipse.keyple:keyple-common-java-api:2.0.+'
implementation 'org.eclipse.keyple:keyple-util-java-lib:2.+'
implementation 'org.eclipse.keyple:keyple-service-java-lib:2.0.1'
implementation 'com.springcard.keyple:keyple-plugin-springcard-android-pcsclike-java-lib:1.0.0'
```
### Gradle Kotlin
```kotlin
implementation("org.calypsonet.terminal:calypsonet-terminal-reader-java-api:1.0.+")
implementation("org.eclipse.keyple:keyple-common-java-api:2.0.+")
implementation("org.eclipse.keyple:keyple-util-java-lib:2.+")
implementation("org.eclipse.keyple:keyple-service-java-lib:2.0.1")
implementation("com.springcard.keyple:keyple-plugin-springcard-android-pcsclike-java-lib:1.0.0")
```
### Maven
```mvn
org.calypsonet.terminal
calypsonet-terminal-reader-java-api
[1.0.0,1.1.0)
org.eclipse.keyple
keyple-common-java-api
[2.0.0,2.1.0)
org.eclipse.keyple
keyple-util-java-lib
[2.0.0,3.0.0)
org.eclipse.keyple
keyple-service-java-lib
2.0.1
com.springcard.keyple
keyple-plugin-springcard-android-pcsclike-java-lib
1.0.0
```
## Initialization of the plugin
The first thing to do to use this plugin is to get a factory with [AndroidPcsclikePluginFactoryProvider] by providing it with
- the type of device ([AndroidPcsclikePluginFactory.DeviceType]),
- the Android context.
```kotlin
// initialization
pluginFactory = AndroidPcsclikePluginFactoryProvider.getFactory(AndroidPcsclikePluginFactory.DeviceType.USB, activity)
// registration
androidPcsclikePlugin = smartCardService.registerPlugin(pluginFactory) as ObservablePlugin
```
## Register and observe
Submit the obtained factory to the smart card service of Keyple and get back the plugin.
Become an observer of the plugin to retrieve the readers from the events generated during their connection.
```kotlin
// set up observation
androidPcsclikePlugin.setPluginObservationExceptionHandler(this)
androidPcsclikePlugin.addObserver(this)
```
## Reader discovery
Start the device scanning with [AndroidPcsclikePlugin.scanDevices].
Handle the result received by the class implementing *DeviceScannerSpi*.
```kotlin
// discover readers
androidPcsclikePlugin
.getExtension(AndroidPcsclikePlugin::class.java)
.scanDevices(2, true, this)
override fun onDeviceDiscovered(deviceInfoList: MutableCollection) {
// connect to first discovered device
if (deviceInfoList.isNotEmpty()) {
val device = deviceInfoList.first()
androidPcsclikePlugin
.getExtension(AndroidPcsclikePlugin::class.java)
.connectToDevice(device.identifier)
} else {
// handle empty list
}
}
```
Become an observer of the needed reader.
```kotlin
override fun onPluginEvent(pluginEvent: PluginEvent?) {
if (pluginEvent != null) {
if (pluginEvent.type == PluginEvent.Type.READER_CONNECTED) {
// connect to the reader identified by its name
for (readerName in pluginEvent.readerNames) {
if (readerName.toUpperCase().contains("CONTACTLESS")) {
cardReader = androidPcsclikePlugin.getReader(readerName) as ObservableReader
if (cardReader != null) {
cardReader!!.getExtension(AndroidPcscReader::class.java)
.setContactless(true)
cardReader!!.setReaderObservationExceptionHandler { pluginName, readerName, e ->
// handle plugin observation exception here
}
cardReader!!.addObserver(this)
cardReader!!.startCardDetection(ObservableCardReader.DetectionMode.REPEATING)
// prepare scheduled selection here
}
}
}
if (pluginEvent.type == PluginEvent.Type.READER_DISCONNECTED) {
for (readerName in pluginEvent.readerNames) {
// notify reader disconnection
}
}
}
}
}
```
## Example application
An example of implementation is available in the **example-app** folder.
This example implements the plugin with the choice of USB or BLE mode.
The card scenario corresponds to a Calypso transaction with or without SAM.
It has been tested with SpringCard readers [Puck One](https://www.springcard.com/fr/products/puck-one) et [Puck Blue](https://www.springcard.com/fr/products/puck-blue)
## About the source code
The code is built with **Gradle** and is compliant with **Java 1.8** in order to address a wide range of applications.
The formatting of the code is kept clean by [spotless](https://github.com/diffplug/spotless).