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(
ParcelUuid.fromString("21f8190c-e4bc-11ed-b5ea-0242ac120001"),
WPTCoder.aes(
"MyApplicationDemoSalt!".toByteArray(), // static data
"7x9ZEvEVf4IqlBxuYmzKhw==".decodeBase64()!!.toByteArray() // 16 bytes encoded in Base64
)
)
constructor(appContext: Context) {
this.target = WPTTarget(appContext, config)
this.target.start { result ->
result.onSuccess {
// target start success, start QR scanning
}.onFailure { error ->
if (error is WPTTargetError) {
// process WPTTargetError
}
}
}
}
}
Classes used for the target
WPTTarget
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
}
Read next
Last updated on Feb 01, 2024 (13:48)
Edit on Github
Send Feedback