现在的位置: 首页 > 综合 > 正文

Android应用程序的debug属性

2012年02月12日 ⁄ 综合 ⁄ 共 1733字 ⁄ 字号 评论关闭

本文参照:http://blog.csdn.net/fyh2003/article/details/6861981

在开发Android应用程序时,我们可以在AndroidManifest.xml中设置其debug属性,比如示例1
示例1

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" 
        android:debuggable="true">

只有android:debuggable="true"时我们才可以在手机上调试Android程序。
但是当我们没在AndroidManifest.xml中设置其debug属性时:
使用Eclipse运行这种方式打包时其debug属性为true,使用Eclipse导出这种方式打包时其debug属性为法false.
在使用ant打包时,其值就取决于ant的打包参数是release还是debug.

 因此在AndroidMainifest.xml中最好设置android:debuggable属性置,而是由打包方式来决定其值。。
  当然对于测试人员还是应该检查该属性的,比如使用aapt工具
  aapt list -v -a myfile.apk
 这个命令将会打印和apk相关的所有详细信息,找到“android:debuggable",它的值分为:
  0x0: debuggable false
  0xffffffff: debugabble true
  例如,在我的测试中,这一行的信息是:
 A: android ebuggable(0x0101000f)=(type 0x12)0x0
 这说明我的Release Build已经关闭了debuggable!
 另外,还有一种测试方法:
  使用android cts测试,http://source.android.com/compatibility/cts-intro.html
  这是一种单元测试的方法,具体用到的类是android.permission.cts.DebuggableTest。
  testNoDebuggable:如果是true,说明debuggable false;
  testNoDebuggable:如果是false,说明debuggable true。
当然,我们也可以在Android应用程序中来判断当前应用是否处于debug状态来做一些操作,如示例2
示例2

    public static boolean isApkDebugable(Context context) {
        try {
            ApplicationInfo info= context.getApplicationInfo();
                return (info.flags&ApplicationInfo.FLAG_DEBUGGABLE)!=0;
        } catch (Exception e) {
            
        }
        return false;
    }

另外,我们也可以在Android应用程序中来判断当前其他应用程序是否处于debug状态,如示例3
示例3

    public static boolean isApkDebugable(Context context,String packageName) {
        try {
            PackageInfo pkginfo = context.getPackageManager().getPackageInfo(
                    packageName, 1);
            if (pkginfo != null ) {
                ApplicationInfo info= pkginfo.applicationInfo;
                return (info.flags&ApplicationInfo.FLAG_DEBUGGABLE)!=0;
            }
            
        } catch (Exception e) {
            
        }
        return false;
    }

结束!

抱歉!评论已关闭.