Skip to content

Instantly share code, notes, and snippets.

@sephiroth74
Created May 31, 2017 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sephiroth74/5c69004b6ac696f0b9dd3dbef5353d0f to your computer and use it in GitHub Desktop.
Save sephiroth74/5c69004b6ac696f0b9dd3dbef5353d0f to your computer and use it in GitHub Desktop.
android instrumentationTest grant permissions
@RunWith(AndroidJUnit4.class)
@LargeTest
public class MyTest {
@Before
public void grantPhonePermission() {
// In M+, trying to call a number will trigger a runtime dialog. Make sure
// the permission is granted before running this test.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
getInstrumentation().getUiAutomation().executeShellCommand(
"pm grant " + getTargetContext().getPackageName()
+ " android.permission.CALL_PHONE");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment