Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Android Cross Device SDK Aims to Simplify Task Handoff and Multi-Device Experiences

Android Cross Device SDK Aims to Simplify Task Handoff and Multi-Device Experiences

Google has announced a developer preview of its new Cross device SDK for Android, aimed to help developers build cross-device experiences using high-level, intuitive APIs.

This SDK abstracts away the intricacies involved with working with device discovery, authentication, and connection protocols, allowing you to focus on what matters most—building delightful user experiences and connecting these experiences across a variety of form factors and platforms.

Device discovery enables finding nearby devices and engage in peer-to-peer communication using secure authentication and end-to-end encryption for bi-directional data sharing. A controlling device can also launch the same app on a target device, which is key to task handoff, where you start a task on a device and continue it on another. According to Google, the new capabilities can be used to create multiplayer games, to carry through productivity tasks across different devices, or to enable group experience, like group food ordering.

The new Cross device SDK provides a higher-level API on top of a number of distinct lower-level APIs, including Bluetooth, Wi-Fi, and Ultra-wide band. To make things easier and more transparent for both developers and users, apps using the Cross device SDK will not need to request permissions for using the underlying services. Instead, the user will authorize their use when enabling an app to communicate with specific devices.

The following code snippet shows how you can start a device discovery session based on the standard OS-provided dialog and launch an activity on a target device:

//-- callback called when the user has completed their device selection
handleDevices = { participants -> participants.forEach {
     // Use participant info

val discoveryClient = Discovery.create(this)
devicePickerLauncher = discoveryClient.registerForResult(this, handleDevices)
  startComponentRequest {
    action = "com.example.crossdevice.MAIN"
    reason = "I want to say hello to you"

On the receiving device, you override two methods, onCreate and onNewIntent, to handle the activity creation if the user accepts the request. For example, you can create a secure connection to exchange data between the devices.

The Sessions API leverages both the discovery and secure connection APIs to provide a higher-level notion of a session that can be created on an originating device and transfer or share with another device capable of handling it.

To make it easier for developers to adopt the new SDK, Google has created a "rock, paper, scissors" app that demonstrates the use of device discovery, secure connections, and session transfer and sharing. Another good starting point for interested developers is the Google I/O ‘22 Multi-device development session.

About the Author

Rate this Article