Android Marshmallow: Test permissions with Espresso?

前端 未结 13 1393
庸人自扰
庸人自扰 2020-11-29 19:31

The new permissions scheme introduced by Android Marshmallow requires checking for specific permissions at runtime, which implies the need to provide different flows dependi

13条回答
  •  悲哀的现实
    2020-11-29 20:13

    Give a try with such static method when your phone is on English locale:

    private static void allowPermissionsIfNeeded() {
        if (Build.VERSION.SDK_INT >= 23) {
            UiDevice device = UiDevice.getInstance(getInstrumentation());
            UiObject allowPermissions = device.findObject(new UiSelector().text("Allow"));
            if (allowPermissions.exists()) {
                try {
                    allowPermissions.click();
                } catch (UiObjectNotFoundException e) {
                    Timber.e(e, "There is no permissions dialog to interact with ");
                }
            }
        }
    }
    

    I found it here

提交回复
热议问题