Android 判断是开发debug模式,还是发布release模式

转载来源http://blog.csdn.net/catoop/article/details/47341125

  1. public class LogUtils {  
  2.   
  3.     public static boolean APP_DBG = false// 是否是debug模式  
  4.       
  5.     public static void init(Context context){  
  6.         APP_DBG = isApkDebugable(context);  
  7.     }  
  8.       
  9.     /** 
  10.      * 但是当我们没在AndroidManifest.xml中设置其debug属性时: 
  11.      * 使用Eclipse运行这种方式打包时其debug属性为true,使用Eclipse导出这种方式打包时其debug属性为法false. 
  12.      * 在使用ant打包时,其值就取决于ant的打包参数是release还是debug. 
  13.      * 因此在AndroidMainifest.xml中最好不设置android:debuggable属性置,而是由打包方式来决定其值. 
  14.      *  
  15.      * @param context 
  16.      * @return 
  17.      * @author SHANHY 
  18.      * @date   2015-8-7 
  19.      */  
  20.     public static boolean isApkDebugable(Context context) {  
  21.         try {  
  22.             ApplicationInfo info= context.getApplicationInfo();  
  23.                 return (info.flags&ApplicationInfo.FLAG_DEBUGGABLE)!=0;  
  24.         } catch (Exception e) {  
  25.               
  26.         }  
  27.         return false;  
  28.     }  
  29.       
  30. }  


项目开发中,我们根据debug属性来输出日志。

但是有些时候我们想在给公司的测试机上安装的release版本也输出日志,那么这个时候我们到 AndroidManifest.xml 中的application 标签中添加属性强制设置debugable即可,如下:

  1. <application android:debuggable="true" tools:ignore="HardcodedDebugMode"  
  2. ....  
  3. .... />  

init 方法在客户端的第一个Activity的onCreate方法中执行一下即可。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值