Created
May 31, 2017 15:34
-
-
Save sephiroth74/5c69004b6ac696f0b9dd3dbef5353d0f to your computer and use it in GitHub Desktop.
android instrumentationTest grant permissions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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