在释放模式下不显示菜单 [英] Don't display menu in release mode

查看:87
本文介绍了在释放模式下不显示菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望为测试条目创建的菜单应该进入调试模式,但是当我释放(启动)我的应用程序时,不应为测试条目显示菜单.有人可以帮我吗?

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?

推荐答案

在应用程序中检查 IS_DEBUG_MODE 标志并在其中添加代码.

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

使用 PackageManager 在您的应用程序上获取 ApplicationInfo 对象,并检查 FLAG_DEBUGGABLE 的标志字段.

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));

更新:

以下解决方案假定开发人员在清单文件中始终设置 android:debuggable = true ,而在应用程序发布时始终设置 android:debuggable = false .

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

现在,您可以通过检查从 PackageManager 获得的 ApplicationInfo 中的 ApplicationInfo.FLAG_DEBUGGABLE 标志来从代码中检查此属性的值.

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
}

在清单文件中:

对于调试时间,

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

关于发布时间,

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

这篇关于在释放模式下不显示菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆