Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only show menu item in debug mode?

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

like image 860
Goldhorn Avatar asked Jul 29 '11 11:07

Goldhorn


2 Answers

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" ... />
like image 102
marioosh Avatar answered Oct 12 '22 12:10

marioosh


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?

like image 37
Vino Avatar answered Oct 12 '22 12:10

Vino