目前,我在清单中使用debuggable属性,它最初并未在文件中设置,因为Eclipse在此上皱眉。然后,在我的ant脚本中,我创建了一个custom_rules.xml,其中我根据目标手动设置清单中的属性,如果释放并且如果调试版本为true,则为false。
<target name="-set-debug-files" depends="-set-mode-check">
.....
<!-- alter the app manifest to reflect the testing state -->
<property name="match.start" value="android:debuggable="/>
<property name="match.end" value=">"/>
<replaceregexp file="AndroidManifest.xml"
match="${match.start}.*${match.end}"
replace="${match.start}"true"${match.end}">
</replaceregexp>
<echo level="info">${ant.project.name}
setting manifest debug state to true</echo>
</target>
<target name="-set-release-mode" depends="-set-mode-check">
......
<property name="match.start" value="android:debuggable="/>
<property name="match.end" value=">"/>
<replaceregexp file="AndroidManifest.xml"
match="${match.start}.*${match.end}"
replace="${match.start}"false"${match.end}">
</replaceregexp>
<echo level="info">${ant.project.name}
setting manifest debug state to false</echo>
</target>
然后在代码中我放置在我的自定义应用程序类中,我创建了一个静态我可以参考我的活动。
DEBUG = (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
然后,当我需要隐藏/显示的东西,我用:
if (MyApplication.DEBUGGABLE) {
...show stuff
} else {
...hide stuff
}
来源
2013-07-18 19:45:36
JPM