Transfer Target

The transfer target is the device that will receive data from another device.

In terms of Bluetooth, the transfer source is the one that is broadcasting to another device.

Example integration

data class MyTransferData(
    val id: String,
    val token: String

class MySampleTarget {

    val target: WPTTarget
    val config = WPTConfig(
            "MyApplicationDemoSalt!".toByteArray(), // static data
            "7x9ZEvEVf4IqlBxuYmzKhw==".decodeBase64()!!.toByteArray() // 16 bytes encoded in Base64

    constructor(appContext: Context) { = WPTTarget(appContext, config) { result ->
            result.onSuccess {
                try {
                    // target start success, start QR scanning
                    // following is an example of how to process the scanned QR code
                    val scannedQRCode = "base64encodedStringRetrievedByQRScanner"
                    val plain = qrContent.decodeBase64()!!
                    val decoded = target.decode(plain.toByteArray())
                    val decodedString = String(decoded)
                    val result = Gson().fromJson(decodedString,
                } catch (e: Exception) {
                    // process exception
            }.onFailure { error ->
                if (error is WPTTargetError) {
                    // process WPTTargetError

Classes used for the target


Entrypoint for the target. Just start the target and instruct the user to scan the QR code that will be prepared on the source device.

Kotlin pseudo-interface of the class

class WPTTarget {

     * Creates a new target.
     * @param context The application context.   
     * @param config The configuration of the target.
    constructor(context: Context, config: WPTConfig)

     * Starts the broadcasting.
     * @param completion The completion callback. When an error occurs, it is the type of [WPTTargetError]
    fun start(completion: (Result<Unit>) -> Unit)
     * Stops the broadcasting.
     * @param completion The completion callback. When an error occurs, it is the type of [WPTTargetError].
    fun stop(completion: (Result<Unit>) -> Unit)
    /** Returns true if the target is broadcasting. */
    fun isRunning(): Bool
     * Decodes the data scanned via QR scanner
     * @param data Data scanned via QR scanner.
     * @return Decoded data.
    @Throws fun decode(data: ByteArray): ByteArray


An error that can occur during the target start/stop operation

class WPTTargetError: Throwable {

    /** The reason of the error. */
    val reason: Reason
    /** The permission that is missing in case of the [Reason.BLUETOOTH_PERMISSION_NOT_GRANTED]. */
    val permission: String?

    enum class Reason {
        /** Already started or stopped */
        /** Bluetooth permission not granted. Use WPTPermissions to ask for permissions. */
        /** Bluetooth is turned off. */
        /** Bluetooth is not supported by this device. */
        /** Data for the Bluetooth are too large (this is a library/platform error). */
        /** Bluetooth is not supported by this device. */
        /** Internal Bluetooth error */
        /** Too many advertisers are advertising */
        /** Unknown error */
Last updated on Feb 05, 2024 (11:35) Edit on Github Send Feedback


Proximity Transfer for Android