Display only menu item in debug mode?

In my application, I created a test page with some code that will be available only to the developer. This page / action can only be achieved through the menu item. Is there a way to determine if an Android application is running in debug mode, and only show a menu item, if true?

Regards, Goldhorn

+5
source share
3 answers

You need to check if debuggable = "true" is set in AndroidManifest.xml. See This Post for more information - Getting the "debuggable" androidManifest value from code?

+3
source

XML , resValue build.gradle, .

buildTypes {
    release {
        ...
        resValue "bool", "DEBUG", "false"
    }
    debug {
        ...
        resValue "bool", "DEBUG", "true"
    }
}

generated.xml :

<?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>

menu.xml:

<item android:visible="@bool/DEBUG" ... />
+4

USE THIS HACK

TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String nOp = tm.getNetworkOperatorName();
if("Android".equals(nOp)) {
    // ADD YOUR MENUS FOR EMULATOR
}
else {
    // ADD YOUR MENUS FOR DEVICE
}
-3
source

All Articles