ProjectedActivityCompat


@ExperimentalProjectedApi
public final class ProjectedActivityCompat implements AutoCloseable


Class providing Projected device-specific features for Activity, like listening to Projected input events.

Use create to create an instance of this class. Use close to clear the instance.

Summary

Public methods

void
static final @NonNull ProjectedActivityCompat
@RequiresApi(value = 34)
create(@NonNull Activity activity)

Connects to the service providing features for Projected devices and returns the ProjectedActivityCompat when the connection is established.

static final @NonNull ProjectedActivityCompat

This method is deprecated. Use create(activity: Activity) instead

final @NonNull Flow<@NonNull ProjectedInputEvent>

Flow providing a stream of Projected input events.

static final void
@WorkerThread
@RequiresApi(value = 35)
requestPermissions(
    @NonNull Activity activity,
    @NonNull String[] permissions,
    @IntRange(from = 0) int requestCode
)

Requests permissions to be granted to this application.

Public methods

close

Added in 1.0.0-alpha10
public void close()

create

@RequiresApi(value = 34)
public static final @NonNull ProjectedActivityCompat create(@NonNull Activity activity)

Connects to the service providing features for Projected devices and returns the ProjectedActivityCompat when the connection is established.

Parameters
@NonNull Activity activity

The Activity running on a Projected device

Throws
IllegalStateException

if the projected service is not found or binding is not permitted

IllegalArgumentException

if provided Activity is not running on a Projected device

create

public static final @NonNull ProjectedActivityCompat create(@NonNull Context context)

Connects to the service providing features for Projected devices and returns the ProjectedActivityCompat when the connection is established.

Use ProjectedActivityCompat.create(activity: Activity) instead

TODO(b/479214966): Remove this once all clients have been migrated.

Parameters
@NonNull Context context

The context to use for binding to the service.

Throws
IllegalStateException

if the projected service is not found or binding is not permitted

getProjectedInputEvents

Added in 1.0.0-alpha10
public final @NonNull Flow<@NonNull ProjectedInputEventgetProjectedInputEvents()

Flow providing a stream of Projected input events.

requestPermissions

Added in 1.0.0-alpha10
@WorkerThread
@RequiresApi(value = 35)
public static final void requestPermissions(
    @NonNull Activity activity,
    @NonNull String[] permissions,
    @IntRange(from = 0) int requestCode
)

Requests permissions to be granted to this application. These permissions must be declared in your manifest, they should not be granted to your app, and they should have protection level dangerous, regardless of whether they are declared by the platform or a third-party app.

When this method is called from a Projected Activity, a new activity will be launched on the Projected device and another activity will be launched on the host device (e.g. phone). The Projected activity will request the user to go to the host activity to act on the permission request. The host activity will request permissions on behalf of the calling application and the system dialog for permission requests will appear for the user to grant/deny the permission.

After the user has acted on the permission request, both the Projected activity and host activity will finish and the results will be delivered to the Activity.onRequestPermissionsResult method overridden by the activity passed to this method.

Throws
IllegalStateException

if the projected service is not found or binding is not permitted

IllegalArgumentException

if provided Activity is not running on a Projected device