Don't display menu in release mode

岁酱吖の 提交于 2019-12-05 05:43:42

问题


I want that the menu i have created for testing entries should come in debug mode but when i release(launch) my application the menu should not be displayed for testing entries. Can anyone help me for this?


回答1:


Check for IS_DEBUG_MODE flag in your application and add code in that..

Use PackageManager to get an ApplicationInfo object on your application, and check the flags field for FLAG_DEBUGGABLE.

boolean isDebuggable = (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE));

Update:

The following solution assumes that in manifest file you always set android:debuggable=true while developing and android:debuggable=false for application release.

Now you can check this attribute's value from your code by checking the ApplicationInfo.FLAG_DEBUGGABLE flag in the ApplicationInfo obtained from PackageManager.

The following code snippet could help:

PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
int flags = packageInfo.applicationInfo.flags; 
if ((flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
    // development mode
} else {
    // release mode
}

So in your manifest file:

For debug time,

<application android:name=".MyActivity" android:icon="@drawable/myicon"
    android:label="@string/app_name" android:debuggable="true">

For release time,

<application android:name=".MyActivity" android:icon="@drawable/myicon"
    android:label="@string/app_name" android:debuggable="false">


来源:https://stackoverflow.com/questions/9747823/dont-display-menu-in-release-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!