本文參照: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; }結束!