DtdiClient

@DoNotMock("Use canonical fakes instead.") interface DtdiClient : HasApiKey<NoOptions>
com.google.android.gms.dtdi.core.DtdiClient

A client for the DTDI Discovery API

Summary

Public methods

abstract Task<Void>
closeConnection(channelInfo: ChannelInfo, token: IBinder, closeReason: String?)

Closes the connection.

abstract Task<Void>

Closes the device.

abstract Task<IntentSender>
createDevicePickerIntent(deviceFilters: List<DeviceFilter>, allowMultipleDeviceSelection: Boolean, wakeupRequest: WakeUpRequest, parentCorrelationData: CorrelationData?)

Creates an IntentSender for a device picker that allows the user to select one or more devices matching the given device filter.

abstract Task<Void>
registerPayloadReceiver(channelInfo: ChannelInfo, token: IBinder, onPayloadReceivedCallback: OnPayloadReceivedCallback)

Registers a payload receiver to receive payload from a named channel on a remote device.

abstract Task<Void>
sendPayload(channelInfo: ChannelInfo, token: IBinder, bytes: ByteArray)

Sends raw bytes to a remote device over a named channel.

Companion functions

GetDevicesResult?
getDevicesResultFromActivityResult(@IntRange(-1) resultCode: Int, resultData: Intent)

Returns the GetDevicesResult object stored in the result data.

Public methods

closeConnection

@RequiresGmsVersion(222600000) abstract fun closeConnection(
    channelInfo: ChannelInfo,
    token: IBinder,
    closeReason: String?
): Task<Void>

Closes the connection. Stop receiving payloads from a named channel on a remote device. The OnPayloadReceivedCallback that previously passed to registerPayloadReceiver will be unregistered.

Parameters
channelInfo: ChannelInfo a tuple of channel name and channel type that can uniquely identify a channel on the app.
token: IBinder A token for a remote device from SelectedDevice.
closeReason: String? An optional reason to indicate to the remote device the reason for closing.
Return
Task for the operation. Task failures are sent out as ApiException with CommonStatusCodes.

closeDevice

@RequiresGmsVersion(222600000) abstract fun closeDevice(token: IBinder): Task<Void>

Closes the device. Devices previously returned from SelectedDevice should be closed to free any resources used.

Parameters
token: IBinder A token for the remote device from SelectedDevice.token.

createDevicePickerIntent

@RequiresGmsVersion(222600000) abstract fun createDevicePickerIntent(
    deviceFilters: List<DeviceFilter>,
    allowMultipleDeviceSelection: Boolean,
    wakeupRequest: WakeUpRequest,
    parentCorrelationData: CorrelationData?
): Task<IntentSender>

Creates an IntentSender for a device picker that allows the user to select one or more devices matching the given device filter.

The calling app should start IntentSender with startIntentSenderForResult and if the result code is RESULT_OK, get the list of devices from the result data.

The result data bundle contains the following fields:

Parameters
deviceFilters: List<DeviceFilter> Only devices that pass all filters will be shown to the user.
allowMultipleDeviceSelection: Boolean Whether or not to allow selecting multiple devices.
wakeupRequest: WakeUpRequest The request used to indicate the activity or component to wake up on the receiving device.
parentCorrelationData: CorrelationData? A parent correlation data to correlate multiple invocations of this method, or null for calls not part of a larger experience.
Return
Task with the IntentSender for the device picker.

registerPayloadReceiver

@RequiresGmsVersion(222600000) abstract fun registerPayloadReceiver(
    channelInfo: ChannelInfo,
    token: IBinder,
    onPayloadReceivedCallback: OnPayloadReceivedCallback
): Task<Void>

Registers a payload receiver to receive payload from a named channel on a remote device. If the given channel already has a receiver, an ApiException with DEVELOPER_ERROR will be thrown.

Parameters
channelInfo: ChannelInfo a tuple of channel name and channel type that can uniquely identify a channel on the app.
token: IBinder A token for a remote device from SelectedDevice.
onPayloadReceivedCallback: OnPayloadReceivedCallback The callback to call when a payload is received.
Return
Task for the operation. Task failures are sent out as ApiException with CommonStatusCodes.

sendPayload

@RequiresGmsVersion(222600000) abstract fun sendPayload(
    channelInfo: ChannelInfo,
    token: IBinder,
    bytes: ByteArray
): Task<Void>

Sends raw bytes to a remote device over a named channel. If the named channel doesn't exist, it will be created before sending the first payload.

Parameters
channelInfo: ChannelInfo a tuple of channel name and channel type that can uniquely identify a channel on the app.
token: IBinder A token for a remote device from SelectedDevice.
bytes: ByteArray Byte array to send to the remote device.
Return
Task for the operation. Task failures are sent out as ApiException with CommonStatusCodes.

Companion functions

getDevicesResultFromActivityResult

@RequiresGmsVersion(222600000) fun getDevicesResultFromActivityResult(
    @IntRange(-1) resultCode: Int,
    resultData: Intent
): GetDevicesResult?

Returns the GetDevicesResult object stored in the result data. The result data passed to this method should be returned from DevicePickerActivity.