In my app I have created a test page with some code that only will be available for the developer. This page/activity can only be reached via a menu-item. Is there a way to determine if an android app is running in debug mode, and only show the menu-item when this is true?
regards, Goldhorn
To directly check debug mode in menu or another resource XML, we can define resValue in build.gradle
like below.
buildTypes {
release {
...
resValue "bool", "DEBUG", "false"
}
debug {
...
resValue "bool", "DEBUG", "true"
}
}
In generated.xml
we will get:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Automatically generated file. DO NOT MODIFY -->
<!-- Values from build type: debug -->
<bool name="DEBUG">true</bool>
</resources>
Now we can use this values and in menu.xml
:
<item android:visible="@bool/DEBUG" ... />
You need to check if the debuggable="true" is set in AndroidManifest.xml. See this post for more info - Getting "debuggable" value of androidManifest from code?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With