ProjectedPermissionsResultContract


class ProjectedPermissionsResultContract : ActivityResultContract


An ActivityResultContract to request permissions from a Projected Activity.

This contract is intended to be used with androidx.activity.result.ActivityResultCaller#registerForActivityResult, but can also be used by directly calling createIntent and parseResult.

When this ActivityResultContract is launched 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 present the user with the rationale for the permission request (if provided) along with buttons to accept or reject. If accepted, the system dialog for permission requests will appear for the user to grant/deny the permission.

If a rationale is not provided, the host activity will immediately trigger the system dialog for permission requests.

After the user has acted on the permission request, both the Projected activity and host activity will finish. The callback provided to androidx.activity.result.ActivityResultCaller#registerForActivityResult will be invoked with a Map of permission results. The keys are the permission names and the values are booleans indicating whether the permission was granted.

If multiple ProjectedPermissionsRequestParams are provided, they will be presented to the user in order. If the user rejects a request, the host activity will automatically advance to the next ProjectedPermissionsRequestParams with a rationale, implicitly rejecting all ProjectedPermissionsRequestParams in between (if any). This prevents a confusing user experience where the user is immediately prompted for a permission after hitting cancel in the rationale UI.

Summary

Public constructors

Public functions

open Intent
@RequiresApi(value = 34)
createIntent(
    context: Context,
    input: List<ProjectedPermissionsRequestParams>
)

Create an intent that can be used for android.app.Activity.startActivityForResult.

open Map<StringBoolean>
parseResult(resultCode: Int, intent: Intent?)

Convert result obtained from android.app.Activity.onActivityResult to O.

Inherited functions

From androidx.activity.result.contract.ActivityResultContract
open ActivityResultContract.SynchronousResult<Map<StringBoolean>>?

An optional method you can implement that can be used to potentially provide a result in lieu of starting an activity.

Public constructors

ProjectedPermissionsResultContract

Added in 1.0.0-alpha01
ProjectedPermissionsResultContract()

Public functions

createIntent

Added in 1.0.0-alpha01
@RequiresApi(value = 34)
open fun createIntent(
    context: Context,
    input: List<ProjectedPermissionsRequestParams>
): Intent

Create an intent that can be used for android.app.Activity.startActivityForResult.

parseResult

Added in 1.0.0-alpha01
open fun parseResult(resultCode: Int, intent: Intent?): Map<StringBoolean>

Convert result obtained from android.app.Activity.onActivityResult to O.