ProjectedPermissionsResultContract


public final class ProjectedPermissionsResultContract extends 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 methods

@NonNull Intent

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

@NonNull Map<@NonNull String, @NonNull Boolean>
parseResult(int resultCode, Intent intent)

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

Inherited methods

From androidx.activity.result.contract.ActivityResultContract
ActivityResultContract.SynchronousResult<@NonNull Map<@NonNull String, @NonNull Boolean>>

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
public ProjectedPermissionsResultContract()

Public methods

createIntent

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

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

parseResult

Added in 1.0.0-alpha01
public @NonNull Map<@NonNull String, @NonNull BooleanparseResult(int resultCode, Intent intent)

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