# Connect to a reader Connect your application to a Stripe Terminal reader. > If you haven’t chosen a reader yet, compare the available [Terminal readers](https://docs.stripe.com/terminal/payments/setup-reader.md) and choose one that best suits your needs. # USB Readers Use the Stripe Terminal Android SDK 3.0.0 (or later) to support USB connections for the [Stripe Reader M2](https://docs.stripe.com/terminal/payments/setup-reader/stripe-m2.md) and [BBPOS WisePad 3](https://docs.stripe.com/terminal/payments/setup-reader/bbpos-wisepad3.md) readers. You must use a USB cable that supports both data and charging, like the USB 2.0 cable that’s included with the Stripe Reader M2 and BBPOS WisePad 3. If the cable included with your Terminal reader is charge-only, use a third-party USB 2.0 cable that can also transfer data. To connect your app to a Terminal reader with a USB cable: 1. [Discover readers](https://docs.stripe.com/terminal/payments/connect-reader.md#discover-readers). 2. [Connect to a reader](https://docs.stripe.com/terminal/payments/connect-reader.md#connect-reader). ## Discover readers [Client-side] - [discoverReaders (Android)](https://stripe.dev/stripe-terminal-android/core/com.stripe.stripeterminal/-terminal/discover-readers.html) - [UsbDiscoveryConfiguration (Android)](https://stripe.dev/stripe-terminal-android/external/com.stripe.stripeterminal.external.models/-discovery-configuration/-usb-discovery-configuration/index.html) Make sure the reader is powered on and connected with a USB 2.0 cable to the device running your app, and permission has been granted to access the USB-connected reader. If you’re plugging in the reader for the first time, an Android system prompt displays to connect to the reader. You can select the “Always open” checkbox to open your app without prompting when it’s connected to a reader. Then from your app, search for the connected reader with the `discoverReaders` method, using `UsbDiscoveryConfiguration`. #### Kotlin ```kotlin class DiscoverReadersActivity : AppCompatActivity(), DiscoveryListener { // ... var discoverCancelable: Cancelable? = null // Action for a "Discover Readers" button fun discoverReadersAction() { val timeout = 0 val isSimulated = false val config = UsbDiscoveryConfiguration( timeout = timeout, isSimulated = isSimulated ) Terminal.getInstance().discoverReaders( config, this, object : Callback { override fun onSuccess() { // Placeholder for handling successful operation } override fun onFailure(e: TerminalException) { // Placeholder for handling exception } } ) } override fun onUpdateDiscoveredReaders(readers: List) { // In your app, display the discovered readers to the user. // Call `connectReader` after the user selects a reader to connect to. } // ... } ``` ## Connect to a reader [Client-side] - [connectReader (Android)](https://stripe.dev/stripe-terminal-android/core/com.stripe.stripeterminal/-terminal/connect-reader.html) - [UsbConnectionConfiguration (Android)](https://stripe.dev/stripe-terminal-android/external/com.stripe.stripeterminal.external.models/-connection-configuration/-usb-connection-configuration/index.html) To connect to a discovered reader, call the `connectReader` method from your app. Mobile readers don’t need to be registered in the Dashboard or API ahead of time. Instead, you associate your mobile reader with a [location](https://docs.stripe.com/api/terminal/locations.md) at connection time. To do so, create and use a `UsbConnectionConfiguration` with the `locationId` set to the relevant location ID when connecting. #### Kotlin ```kotlin // Implement your MobileReaderListener val mobileReaderListener = yourMobileReaderListener val autoReconnectOnUnexpectedDisconnect = true val connectionConfig = UsbConnectionConfiguration( ""{{LOCATION_ID}}"", autoReconnectOnUnexpectedDisconnect, mobileReaderListener ) Terminal.getInstance().connectReader( selectedReader, connectionConfig, object : ReaderCallback { override fun onSuccess(reader: Reader) { // Placeholder for handling successful operation } override fun onFailure(e: TerminalException) { // Placeholder for handling exception } } ) ``` > #### Use standby mode > > Don’t program your app to call `disconnectReader` to conserve power. The reader efficiently handles power management using its standby mode. ## Handle reader disconnects - [MobileReaderListener (Android)](https://stripe.dev/stripe-terminal-android/external/com.stripe.stripeterminal.external.callable/-mobile-reader-listener/index.html) - [DisconnectReason (Android)](https://stripe.dev/stripe-terminal-android/external/com.stripe.stripeterminal.external.models/-disconnect-reason/index.html) Reader disconnects can sometimes occur between your app and the reader. For example, the reader can disconnect from your app if the USB cable connecting it to your device is disconnected. You can simulate an unexpected disconnect while testing by powering off the reader. The `MobileReaderListener` includes an `onDisconnect` callback that provides your application with the `DisconnectReason` to help identify why the reader disconnected. To handle reader disconnects yourself, you can do the following: 1. Set `autoReconnectOnUnexpectedDisconnect` to `false` during connection. 2. Handle the disconnect callback to display a message in the app alerting the user that the reader unexpectedly disconnected and initiate reader discovery and connection. #### Kotlin ```kotlin class ReaderActivity : AppCompatActivity(), MobileReaderListener { // ... override fun onDisconnect(reason: DisconnectReason) { // Consider displaying a UI to notify the user and start rediscovering readers } // ... } ``` ### Reboot the connected reader - [rebootReader (Android)](https://stripe.dev/stripe-terminal-android/core/com.stripe.stripeterminal/-terminal/reboot-reader.html) Stripe Reader M2 and BBPOS WisePad 3 automatically reboot after operating for 24 hours. However, you can force the reader to reboot and reset its 24-hour timer by using the `rebootReader` API. After this action, the reader disconnects from the SDK and then reboots. If you’re using automatic reconnect, the SDK attempts to restore the connection with the reader. #### Kotlin ```kotlin Terminal.getInstance().rebootReader( object : Callback { override fun onSuccess() { // Reboot succeeded and the reader will disconnect. // If your app is using automatic reconnect the reconnect will begin. } override fun onFailure(e: TerminalException) { // Placeholder for handling exception } } ) ``` #### Automatically attempt reconnection When a reader disconnects, we automatically attempt reconnection by default and recommend that you display notifications in your app relaying the reader status throughout the process. To display notifications in your app during automatic reconnection, do the following: 1. Implement the reader reconnect callbacks in the `MobileReaderListener`. 2. Pass the `MobileReaderListener` to your `UsbConnectionConfiguration`. #### Kotlin ```kotlin val mobileReaderListener = yourMobileReaderListener val autoReconnectOnUnexpectedDisconnect = true Terminal.getInstance().connectReader( reader, UsbConnectionConfiguration( ""{{LOCATION_ID}}"", autoReconnectOnUnexpectedDisconnect, mobileReaderListener ), object : ReaderCallback { override fun onSuccess(reader: Reader) { // Placeholder for handling successful operation } override fun onFailure(e: TerminalException) { // Placeholder for handling exception } } ) ``` 3. When the SDK sends [onReaderReconnectStarted](https://stripe.dev/stripe-terminal-android/external/com.stripe.stripeterminal.external.callable/-reader-reconnection-listener/on-reader-reconnect-started.html) to your app, display a message announcing that the reader lost connection and reconnection is in progress. - You can use the `Cancelable` object to stop the reconnection attempt at any time. 4. When the SDK indicates successful reconnection by sending [`onReaderReconnectSucceeded`](https://stripe.dev/stripe-terminal-android/external/com.stripe.stripeterminal.external.callable/-reader-reconnection-listener/on-reader-reconnect-succeeded.html), display a message announcing the connection was restored and to continue normal operations. 5. If the SDK can’t reconnect to the reader and sends both [`onReaderReconnectFailed`](https://stripe.dev/stripe-terminal-android/external/com.stripe.stripeterminal.external.callable/-reader-reconnection-listener/on-reader-reconnect-failed.html) and `onDisconnect`, display a message stating that an unexpected disconnect occurred. #### Kotlin ```kotlin class CustomMobileReaderListener : MobileReaderListener { // ... override fun onReaderReconnectStarted(reader: Reader, cancelReconnect: Cancelable, reason: DisconnectReason) { // 1. Notified at the start of a reconnection attempt // Use cancelable to stop reconnection at any time } override fun onReaderReconnectSucceeded(reader: Reader) { // 2. Notified when reader reconnection succeeds // App is now connected } override fun onReaderReconnectFailed(reader: Reader) { // 3. Notified when reader reconnection fails // App is now disconnected } // ... } ``` #### Automatic reconnection on application start Stripe Terminal doesn’t automatically reconnect to a reader when your application starts. Instead, you can build a reconnection flow by storing reader IDs and attempting to connect to a known reader on startup. 1. When you successfully connect to a reader, save its serial number in a persistent data storage location, such as the [Shared Preferences API](https://developer.android.com/training/data-storage/shared-preferences) (Android). 1. When your app launches, check the persistent data storage location for a saved serial number. If one is found, call the `discoverReaders` method so your application can try to find that reader again. 2. If the saved serial number matches any of the discovered readers, try connecting to that reader with the matching reader object returned from the call to `discoverReaders`. If the previously connected reader isn’t found, stop the discovery process. Display some UI during the discovery and connection process to indicate that an automatic reconnection is happening. ## Update reader software [Client-side] - [MobileReaderListener (Android)](https://stripe.dev/stripe-terminal-android/external/com.stripe.stripeterminal.external.callable/-mobile-reader-listener/index.html) Your application must update mobile readers to apply the following: - Regional configurations that keep you up to date with card network and issuer requirements - Security updates Required updates start installing on connection to the reader. You can’t use the reader until updating completes. > To install updates, the reader’s battery level must be higher than 50%. ### Required updates When immediately required updates are available for the reader, the integration’s `MobileReaderListener` receives `onStartInstallingUpdate` with a `ReaderSoftwareUpdate`. The `ReaderSoftwareUpdate` provides the necessary details of the update, including an estimate of the total update duration, indicated by `durationEstimate`. During the installation process, the Terminal’s `connectionStatus` transitions to `ConnectionStatus.CONNECTING` while the update installs on the reader. Your application must notify users that an update is installing and display the progress in your UI. Make it clear why connecting might take longer than usual. If the required update process fails, Stripe communicates the error to the `MobileReaderListener` with `onFinishInstallingUpdate`. You can’t reconnect to the reader after a required update fails, unless the following conditions are met: - The reader runs the latest software version for the location within the last 30 days. - The Android SDK version is greater than or equal to `3.5.0`. If the conditions are met, the connection process succeeds despite an incomplete update. Stripe retries the required update the next time you connect to that reader until it’s successfully installed. #### Kotlin ```kotlin class ReaderActivity : AppCompatActivity(), MobileReaderListener { // ... override fun onStartInstallingUpdate(update: ReaderSoftwareUpdate, cancelable: Cancelable) { // Show UI communicating that a required update has started installing } override fun onReportReaderSoftwareUpdateProgress(progress: Float) { // Update the progress of the installation } override fun onFinishInstallingUpdate(update: ReaderSoftwareUpdate?, e: TerminalException?) { // Report success or failure of the update } // ... } ``` You can cancel required updates using the `Cancelable` object, which also results in a failed connection to the reader. You can’t cancel in-progress incremental-only updates. ### Optional updates You can defer optional updates until the specified date, after which they become required. The SDK notifies you of optional updates through the `MobileReaderListener` any time the reader is connected but not performing a transaction. If an optional update is available, your application’s `MobileReaderListener` receives the `onReportAvailableUpdate` callback with the `ReaderSoftwareUpdate` object containing the update details, including: - Estimated time for update to complete (`durationEstimate`) - Date after which the update becomes required (`requiredAt`) In your application, notify users that an update is available, and display a prompt to optionally continue with the update. To proceed with the update previously reported with `onReportAvailableUpdate`, call `Terminal.getInstance().installAvailableUpdate`. The available update is also stored on the reader object as `reader.availableUpdate`. As the update proceeds, block the user from leaving the page in your app, and instruct the user to keep the reader connected until the update completes. We recommend also providing your user with a visual indicator of the update’s progress. The `MobileReaderListener` reports the update’s progress in the `onReportReaderSoftwareUpdateProgress` method. When an optional update’s `requiredAt` date has passed, the update installs the next time the reader is connected. #### Kotlin ```kotlin class ReaderActivity : AppCompatActivity(), MobileReaderListener { // ... override fun onReportAvailableUpdate(update: ReaderSoftwareUpdate) { // An update is available for the connected reader. Show this update in your application. // Install this update using `Terminal.getInstance().installAvailableUpdate`. } // ... } ``` See [Testing reader updates](https://docs.stripe.com/terminal/references/testing.md#simulated-reader-updates) to learn more about making sure your application handles the different update types that a reader can have. ## Next steps You’ve connected your application to the reader. Next, [collect your first Stripe Terminal payment](https://docs.stripe.com/terminal/payments/collect-card-payment.md). The BBPOS and Chipper™ name and logo are trademarks or registered trademarks of BBPOS Limited in the United States or other countries. The Verifone® name and logo are either trademarks or registered trademarks of Verifone in the United States and/or other countries. Use of the trademarks doesn’t imply any endorsement by BBPOS or Verifone.