How to grant permissions to android instrumented tests?

Use GrantPermissionRule. Here’s how:

Add the following dependency to app/build.gradle:

dependencies {
    ...
    androidTestImplementation 'androidx.test:rules:1.4.0'
}

Now add the following to your InstrumentedTest class:

import androidx.test.rule.GrantPermissionRule;

public class InstrumentedTest {
    @Rule
    public GrantPermissionRule mRuntimePermissionRule = GrantPermissionRule.grant(Manifest.permission.READ_SMS);
    ...
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)