问题
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