Android應用程式的debug屬性

來源:互聯網
上載者:User

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

結束!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.