Android Permissions

How to grant Android runtime permissions at runtime for Espresso tests.

  1. Check your app permissions: $adb shell dumpsys package com.myApp
  2. Then when you run your test, just call function below:
public void grantLocationPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
getInstrumentation().getUiAutomation().executeShellCommand(
"pm grant " + getTargetContext().getPackageName()
+ " android.permission.CONTACTS"
+ " android.permission.ACCESS_FINE_LOCATION"
+ " android.permission.ACCOUNT_MANAGER");
}
}

Android permissions list: http://www.androidauthority.com/android-app-permissions-explained-642452/

You can reboot device by adding “reboot” to above code snippet :)