ProjectedActivityCompat


@ExperimentalProjectedApi
class ProjectedActivityCompat : 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 companion functions

suspend ProjectedActivityCompat
@RequiresApi(value = 34)
create(activity: Activity)

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

suspend ProjectedActivityCompat
create(context: Context)

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

Unit
@WorkerThread
@RequiresApi(value = 35)
requestPermissions(
    activity: Activity,
    permissions: Array<String>,
    requestCode: @IntRange(from = 0) Int
)

Requests permissions to be granted to this application.

Public functions

open Unit

Public properties

Flow<ProjectedInputEvent>

Flow providing a stream of Projected input events.

Public companion functions

create

@RequiresApi(value = 34)
suspend fun create(activity: Activity): ProjectedActivityCompat

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

Parameters
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

suspend fun create(context: Context): ProjectedActivityCompat

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
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

requestPermissions

Added in 1.0.0-alpha10
@WorkerThread
@RequiresApi(value = 35)
fun requestPermissions(
    activity: Activity,
    permissions: Array<String>,
    requestCode: @IntRange(from = 0) Int
): Unit

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

Public functions

close

Added in 1.0.0-alpha10
open fun close(): Unit

Public properties

projectedInputEvents

Added in 1.0.0-alpha10
val projectedInputEventsFlow<ProjectedInputEvent>

Flow providing a stream of Projected input events.