Enable Screenshots
To unlock full functionality of axe DevTools for Mobile, ensure screenshots are enabled. If you've disabled screenshots on the production version of your app, we recommend enabling screenshots on a debug or test version of your app that uses mock data to avoid security concerns. Screenshots are saved in the JSON result and can be viewed from the Mobile Dashboard. Screenshots allow you to more easily locate and troubleshoot the accessibility issues that are found.
Code
In the build.gradle
file, we'll add a debug configuration that indicates screenshots should be disabled in the release configuration, and enabled in the debug configuration:
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
buildConfigField "boolean", "DISABLE_SCREENSHOT", "true"
}
debug {
buildConfigField "boolean", "DISABLE_SCREENSHOT", "false"
}
}
Now, any activity that is presenting the screenshot can be wrapped in the build configuration. This will allow the screenshot functionality in the debug builds, ensuring your experience with axe DevTools for Mobile is not hindered.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (BuildConfig.DISABLE_SCREENSHOT) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
}
}