如下所示:
public class LogUtils { public static boolean APP_DBG = false; // 是否是debug模式 public static void init(Context context){ APP_DBG = isApkDebugable(context); } /** * 但是當(dāng)我們沒在AndroidManifest.xml中設(shè)置其debug屬性時(shí): * 使用Eclipse運(yùn)行這種方式打包時(shí)其debug屬性為true,使用Eclipse導(dǎo)出這種方式打包時(shí)其debug屬性為法false. * 在使用ant打包時(shí),其值就取決于ant的打包參數(shù)是release還是debug. * 因此在AndroidMainifest.xml中最好不設(shè)置android:debuggable屬性置,而是由打包方式來決定其值. * * @param context * @return * @author SHANHY * @date 2015-8-7 */ public static boolean isApkDebugable(Context context) { try { ApplicationInfo info= context.getApplicationInfo(); return (info.flags&ApplicationInfo.FLAG_DEBUGGABLE)!=0; } catch (Exception e) { } return false; } }項(xiàng)目開發(fā)中,我們根據(jù)debug屬性來輸出日志。
但是有些時(shí)候我們想在給公司的測試機(jī)上安裝的release版本也輸出日志,那么這個(gè)時(shí)候我們到 AndroidManifest.xml 中的application 標(biāo)簽中添加屬性強(qiáng)制設(shè)置debugable即可,如下:
<application android:debuggable="true" tools:ignore="HardcodedDebugMode"........ />
init 方法在客戶端的第一個(gè)Activity的onCreate方法中執(zhí)行一下即可。
以上這篇Android 判斷是開發(fā)debug模式,還是發(fā)布release模式的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選