Android應用程式的debug屬性
http://blog.csdn.net/hudashi/article/details/8698142
本文參照:http://blog.csdn.net/fyh2003/article/details/6861981
在開發Android應用程式時,我們可以在AndroidManifest.xml中設定其debug屬性,比如示例1
示例1
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p><div><span class="pln"> </span><span class="tag" style="color: rgb(0, 0, 136);"><application</span></div><div><span class="pln"> </span><span class="atn" style="color: rgb(102, 0, 102);">android:icon</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="atv" style="color: rgb(0, 136, 0);">"@drawable/ic_launcher"</span></div><div><span class="pln"> </span><span class="atn" style="color: rgb(102, 0, 102);">android:label</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="atv" style="color: rgb(0, 136, 0);">"@string/app_name"</span></div><div><span class="pln"> </span><span class="atn" style="color: rgb(102, 0, 102);">android:theme</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="atv" style="color: rgb(0, 136, 0);">"@style/AppTheme"</span><span class="pln"> </span></div><div><span class="pln"> </span><span class="atn" style="color: rgb(102, 0, 102);">android:debuggable</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="atv" style="color: rgb(0, 136, 0);">"true"</span><span class="tag" style="color: rgb(0, 0, 136);">></span></div><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p>
只有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
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p><div style="line-height: 22px;"><span class="pln" style="line-height: 25px;"> </span><span class="kwd" style="line-height: 25px; color: rgb(0, 0, 136);">public</span><span class="pln" style="line-height: 25px;"> </span><span class="kwd" style="line-height: 25px; color: rgb(0, 0, 136);">static</span><span class="pln" style="line-height: 25px;"> </span><span class="kwd" style="line-height: 25px; color: rgb(0, 0, 136);">boolean</span><span class="pln" style="line-height: 25px;"> isApkDebugable</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">(</span><span class="typ" style="line-height: 25px; color: rgb(102, 0, 102);">Context</span><span class="pln" style="line-height: 25px;"> context</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">)</span><span class="pln" style="line-height: 25px;"> </span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">{</span></div><div style="line-height: 22px;"><span class="pln" style="line-height: 25px;"> </span><span class="kwd" style="line-height: 25px; color: rgb(0, 0, 136);">try</span><span class="pln" style="line-height: 25px;"> </span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">{</span></div><div style="line-height: 22px;"><span class="pln" style="line-height: 25px;"> </span><span class="typ" style="line-height: 25px; color: rgb(102, 0, 102);">ApplicationInfo</span><span class="pln" style="line-height: 25px;"> info</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">=</span><span class="pln" style="line-height: 25px;"> context</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">.</span><span class="pln" style="line-height: 25px;">getApplicationInfo</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">();</span></div><div style="line-height: 22px;"><span class="pln" style="line-height: 25px;"> </span><span class="kwd" style="line-height: 25px; color: rgb(0, 0, 136);">return</span><span class="pln" style="line-height: 25px;"> </span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">(</span><span class="pln" style="line-height: 25px;">info</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">.</span><span class="pln" style="line-height: 25px;">flags</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">&</span><span class="typ" style="line-height: 25px; color: rgb(102, 0, 102);">ApplicationInfo</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">.</span><span class="pln" style="line-height: 25px;">FLAG_DEBUGGABLE</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">)!=</span><span class="lit" style="line-height: 25px; color: rgb(0, 102, 102);">0</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">;</span></div><div style="line-height: 22px;"><span class="pln" style="line-height: 25px;"> </span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">}</span><span class="pln" style="line-height: 25px;"> </span><span class="kwd" style="line-height: 25px; color: rgb(0, 0, 136);">catch</span><span class="pln" style="line-height: 25px;"> </span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">(</span><span class="typ" style="line-height: 25px; color: rgb(102, 0, 102);">Exception</span><span class="pln" style="line-height: 25px;"> e</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">)</span><span class="pln" style="line-height: 25px;"> </span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">{</span></div><div style="line-height: 22px;"><span class="pln" style="line-height: 25px;"> </span></div><div style="line-height: 22px;"><span class="pln" style="line-height: 25px;"> </span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">}</span></div><div style="line-height: 22px;"><span class="pln" style="line-height: 25px;"> </span><span class="kwd" style="line-height: 25px; color: rgb(0, 0, 136);">return</span><span class="pln" style="line-height: 25px;"> </span><span class="kwd" style="line-height: 25px; color: rgb(0, 0, 136);">false</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">;</span></div><div style="line-height: 22px;"><span class="pln" style="line-height: 25px;"> </span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">}</span></div><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p>
另外,我們也可以在Android應用程式中來判斷當前其他應用程式是否處於debug狀態,如示例3。
示例3
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p><div style="line-height: 22px;"><span class="pln" style="line-height: 25px;"> </span><span class="kwd" style="line-height: 25px; color: rgb(0, 0, 136);">public</span><span class="pln" style="line-height: 25px;"> </span><span class="kwd" style="line-height: 25px; color: rgb(0, 0, 136);">static</span><span class="pln" style="line-height: 25px;"> </span><span class="kwd" style="line-height: 25px; color: rgb(0, 0, 136);">boolean</span><span class="pln" style="line-height: 25px;"> isApkDebugable</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">(</span><span class="typ" style="line-height: 25px; color: rgb(102, 0, 102);">Context</span><span class="pln" style="line-height: 25px;"> context</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">,</span><span class="typ" style="line-height: 25px; color: rgb(102, 0, 102);">String</span><span class="pln" style="line-height: 25px;"> packageName</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">)</span><span class="pln" style="line-height: 25px;"> </span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">{</span></div><div style="line-height: 22px;"><span class="pln" style="line-height: 25px;"> </span><span class="kwd" style="line-height: 25px; color: rgb(0, 0, 136);">try</span><span class="pln" style="line-height: 25px;"> </span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">{</span></div><div style="line-height: 22px;"><span class="pln" style="line-height: 25px;"> </span><span class="typ" style="line-height: 25px; color: rgb(102, 0, 102);">PackageInfo</span><span class="pln" style="line-height: 25px;"> pkginfo </span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">=</span><span class="pln" style="line-height: 25px;"> context</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">.</span><span class="pln" style="line-height: 25px;">getPackageManager</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">().</span><span class="pln" style="line-height: 25px;">getPackageInfo</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">(</span></div><div style="line-height: 22px;"><span class="pln" style="line-height: 25px;"> packageName</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">,</span><span class="pln" style="line-height: 25px;"> </span><span class="lit" style="line-height: 25px; color: rgb(0, 102, 102);">1</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">);</span></div><div style="line-height: 22px;"><span class="pln" style="line-height: 25px;"> </span><span class="kwd" style="line-height: 25px; color: rgb(0, 0, 136);">if</span><span class="pln" style="line-height: 25px;"> </span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">(</span><span class="pln" style="line-height: 25px;">pkginfo </span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">!=</span><span class="pln" style="line-height: 25px;"> </span><span class="kwd" style="line-height: 25px; color: rgb(0, 0, 136);">null</span><span class="pln" style="line-height: 25px;"> </span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">)</span><span class="pln" style="line-height: 25px;"> </span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">{</span></div><div style="line-height: 22px;"><span class="pln" style="line-height: 25px;"> </span><span class="typ" style="line-height: 25px; color: rgb(102, 0, 102);">ApplicationInfo</span><span class="pln" style="line-height: 25px;"> info</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">=</span><span class="pln" style="line-height: 25px;"> pkginfo</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">.</span><span class="pln" style="line-height: 25px;">applicationInfo</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">;</span></div><div style="line-height: 22px;"><span class="pln" style="line-height: 25px;"> </span><span class="kwd" style="line-height: 25px; color: rgb(0, 0, 136);">return</span><span class="pln" style="line-height: 25px;"> </span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">(</span><span class="pln" style="line-height: 25px;">info</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">.</span><span class="pln" style="line-height: 25px;">flags</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">&</span><span class="typ" style="line-height: 25px; color: rgb(102, 0, 102);">ApplicationInfo</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">.</span><span class="pln" style="line-height: 25px;">FLAG_DEBUGGABLE</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">)!=</span><span class="lit" style="line-height: 25px; color: rgb(0, 102, 102);">0</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">;</span></div><div style="line-height: 22px;"><span class="pln" style="line-height: 25px;"> </span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">}</span></div><div style="line-height: 22px;"><span class="pln" style="line-height: 25px;"> </span></div><div style="line-height: 22px;"><span class="pln" style="line-height: 25px;"> </span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">}</span><span class="pln" style="line-height: 25px;"> </span><span class="kwd" style="line-height: 25px; color: rgb(0, 0, 136);">catch</span><span class="pln" style="line-height: 25px;"> </span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">(</span><span class="typ" style="line-height: 25px; color: rgb(102, 0, 102);">Exception</span><span class="pln" style="line-height: 25px;"> e</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">)</span><span class="pln" style="line-height: 25px;"> </span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">{</span></div><div style="line-height: 22px;"><span class="pln" style="line-height: 25px;"> </span></div><div style="line-height: 22px;"><span class="pln" style="line-height: 25px;"> </span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">}</span></div><div style="line-height: 22px;"><span class="pln" style="line-height: 25px;"> </span><span class="kwd" style="line-height: 25px; color: rgb(0, 0, 136);">return</span><span class="pln" style="line-height: 25px;"> </span><span class="kwd" style="line-height: 25px; color: rgb(0, 0, 136);">false</span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">;</span></div><div style="line-height: 22px;"><span class="pln" style="line-height: 25px;"> </span><span class="pun" style="line-height: 25px; color: rgb(102, 102, 0);">}</span></div><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p>
結束!
相關文章
- 用程式設定COM+應用程式的屬性。 (轉)
- 應用程式池屬性詳解及配置
- 設定Adobe Air應用程式屬性AI
- Debug模式應用程式輸出Debug除錯資訊模式除錯
- 【Android】神奇的android:clipChildren屬性Android
- 雲原生應用的十個關鍵屬性
- jQuery的動畫效果可以應用與哪些屬性jQuery動畫
- HTML5中margin屬性應用HTML
- Android XML 屬性AndroidXML
- android屬性動畫Android動畫
- android:screenOrientation屬性Android
- Android 《CardView 屬性》AndroidView
- 在MyEclipse中用debug除錯應用程式Eclipse除錯
- debug 和 release 應用
- Spring Boot 2.0.2 參考指南(通用的應用程式屬性 ②)中文文件Spring Boot
- Kotlin基礎:抽象屬性的應用場景Kotlin抽象
- 深入剖析 Java 類屬性與類方法的應用Java
- 深入解析 Java 物件導向程式設計與類屬性應用Java物件程式設計
- 深入理解和應用display屬性(二)
- Android 樣式屬性的使用Android
- Android 屬性動畫(二)Android動畫
- Android 相關屬性Android
- Android屬性之excludeFromRecentsAndroid
- Android自定義屬性Android
- Android介面基本屬性Android
- css屬性與js中style物件的屬性對應表CSSJS物件
- Oracle約束constraint的三個屬性應用OracleAI
- Android屬性動畫詳解(一),屬性動畫基本用法Android動畫
- border-sizing屬性詳解和應用
- 使用 Moq 測試.NET Core 應用 -- Mock 屬性Mock
- HTML5中ol和li屬性應用HTML
- CSS direction屬性簡介與實際應用CSS
- Struts的Indexed屬性用處Index
- Android控制元件的fitSystemWindows屬性Android控制元件Windows
- Android解析WindowManager(二)Window的屬性Android
- Android UI系列-----ImageView的scaleType屬性AndroidUIView
- Android 屬性動畫實戰Android動畫
- Android 動畫之屬性動畫Android動畫