PermissionRequester

public class PermissionRequester
extends Object implements PermissionGranter

java.lang.Object
   ↳ androidx.test.runner.permission.PermissionRequester


Requests a runtime permission on devices running Android M (API 23) and above.

This class is usually used to grant runtime permissions to avoid the permission dialog from showing up and blocking the App's Ui. This is especially helpful for Ui-Testing to avoid loosing control over your application under test.

The requested permissions will be granted for all test methods in the test class. Use addPermissions(String) to add a permission to the permission list. To request all permissions use the requestPermissions() method.

Note: Usually this class would not be used directly, but through GrantPermissionRule.

This API is currently in beta.

Summary

Public constructors

PermissionRequester()

Public methods

void addPermissions(String... permissions)

Adds a permission to the list of permissions which will be requested when requestPermissions() is called.

void requestPermissions()

Request all permissions previously added using addPermissions(String)

Precondition: This method does nothing when called on an API level lower than Build.VERSION_CODES.M.

Protected methods

void setAndroidRuntimeVersion(int sdkInt)

Inherited methods

Public constructors

PermissionRequester

public PermissionRequester ()

Public methods

addPermissions

public void addPermissions (String... permissions)

Adds a permission to the list of permissions which will be requested when requestPermissions() is called.

Precondition: This method does nothing when called on an API level lower than Build.VERSION_CODES.M.

Parameters
permissions String: a list of Android runtime permissions.

requestPermissions

public void requestPermissions ()

Request all permissions previously added using addPermissions(String)

Precondition: This method does nothing when called on an API level lower than Build.VERSION_CODES.M.

Protected methods

setAndroidRuntimeVersion

protected void setAndroidRuntimeVersion (int sdkInt)

Parameters
sdkInt int