Stay organized with collections Save and categorize content based on your preferences.

RemoteActivityHelper

public final class RemoteActivityHelper


Support for opening android intents on other devices.

The following example opens play store for the given app on another device:

val remoteActivityHelper = RemoteActivityHelper(context, executor)

val result = remoteActivityHelper.startRemoteActivity(
new Intent(Intent.ACTION_VIEW).setData(
Uri.parse("http://play.google.com/store/apps/details?id=com.example.myapp")
),
nodeId
)

startRemoteActivity returns a ListenableFuture, which is completed after the intent has been sent or failed if there was an issue with sending the intent.

nodeId is the opaque string that represents a node in the Android Wear network. For the given device, it can obtained by NodeClient.getLocalNode() and the list of nodes to which this device is currently connected can be obtained by NodeClient.getConnectedNodes(). More information about this can be found here.

Summary

Nested types

public static class RemoteActivityHelper.Companion

Constants

static final @NonNull String
static final int

Result code passed to ResultReceiver.send when a remote intent failed to send.

static final int

Result code passed to ResultReceiver.send when a remote intent was sent successfully.

Public constructors

Public methods

static final Intent

Returns the android.content.Intent extra specifying remote intent.

static final String

Returns the String extra specifying node ID of remote intent.

final @NonNull ListenableFuture<@NonNull Void>
startRemoteActivity(@NonNull Intent targetIntent, String targetNodeId)

Start an activity on another device.

Constants

ACTION_REMOTE_INTENT

public static final @NonNull String ACTION_REMOTE_INTENT

RESULT_FAILED

public static final int RESULT_FAILED = 1

Result code passed to ResultReceiver.send when a remote intent failed to send.

RESULT_OK

public static final int RESULT_OK = 0

Result code passed to ResultReceiver.send when a remote intent was sent successfully.

Public constructors

RemoteActivityHelper

public RemoteActivityHelper(@NonNull Context context, @NonNull Executor executor)
Parameters
@NonNull Context context

The Context of the application for sending the intent.

@NonNull Executor executor

Executor used for getting data to be passed in remote intent. If not specified, default will be Executors.newSingleThreadExecutor().

Public methods

getTargetIntent

public static final Intent getTargetIntent(@NonNull Intent intent)

Returns the android.content.Intent extra specifying remote intent.

Parameters
@NonNull Intent intent

The intent holding configuration.

Returns
Intent

The remote intent, or null if none was set.

getTargetNodeId

public static final String getTargetNodeId(@NonNull Intent intent)

Returns the String extra specifying node ID of remote intent.

Parameters
@NonNull Intent intent

The intent holding configuration.

Returns
String

The node id, or null if none was set.

startRemoteActivity

public final @NonNull ListenableFuture<@NonNull VoidstartRemoteActivity(@NonNull Intent targetIntent, String targetNodeId)

Start an activity on another device. This api currently supports sending intents with action set to android.content.Intent.ACTION_VIEW, a data uri populated using android.content.Intent.setData, and with the category android.content.Intent.CATEGORY_BROWSABLE present. If the current device is a watch, the activity will start on the companion phone device. Otherwise, the activity will start on all connected watch devices.

Parameters
@NonNull Intent targetIntent

The intent to open on the remote device. Action must be set to android.content.Intent.ACTION_VIEW, a data uri must be populated using android.content.Intent.setData, and the category android.content.Intent.CATEGORY_BROWSABLE must be present.

String targetNodeId

Wear OS node id for the device where the activity should be started. If null, and the current device is a watch, the activity will start on the companion phone device. Otherwise, the activity will start on all connected watch devices.

Returns
@NonNull ListenableFuture<@NonNull Void>

The ListenableFuture which resolves if starting activity was successful or throws Exception if any errors happens. If there's a problem with starting remote activity, RemoteIntentException will be thrown.