如何检查我的应用程序是否在android中调试? [英] How to check if my app is being debugged in android?

查看:130
本文介绍了如何检查我的应用程序是否在android中调试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以检查我的android应用程序是否已调试(例如DEBUG标志或某物)?我想在调试应用程序时打印一条特殊消息。

Is there a way to check within my android application if it's being debugged, like a DEBUG flag or somthing? I want to print a special message when the application is being debugged.

推荐答案

有两种方法可以检查apk是否在调试中

1。 BuildConfig.DEBUG:

if (BuildConfig.DEBUG) { 
    // do something with debug build
}

注意:如果您使用的是第一个然后确保从您的项目或应用程序导入了BuildConfig。

Note: If you are using the first one then make sure BuildConfig is imported from your project or your app.

2.ApplicationInfo.FLAG_DEBUGGABLE

if (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE)) {
     //Debug APK
}

这篇关于如何检查我的应用程序是否在android中调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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