2013-05-05 49 views
2

我正在構建一個SDK,並且想要在開發模式下更改有關嚴格模式的內容。僅在開發中啓用嚴格模式

如何知道我是否處於代碼開發模式?

+1

什麼是你的發展模式定義是什麼? – 2013-05-05 07:50:42

+0

當我通過USB插入設備,並在模擬器中運行/運行 – 2013-05-05 08:20:50

回答

9

可以使用BuildConfig.DEBUG值,它是由R.java等ADT工具自動生成的。對於未導出的構建,它總是如此,並且當您導出簽名或未簽名的apk時,它將被設置爲false。

if(BuildConfig.DEBUG) { 
    //In debug mode 
} 
-3

在Android手機上使用

  • 設置 - >應用程序 - >未知來源 - 啓用它
  • 設置 - >開發 - > USB調試 - 啓用它
+0

對不起,我需要知道它代碼 – 2013-05-05 08:28:53

+0

您的問題是不明確和誤導。 – Siddharth 2013-05-05 08:29:40

5
if(BuildConfig.DEBUG) { 
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 
    StrictMode.setThreadPolicy(policy); 
} 

if (DEVELOPER_MODE) { 
     StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() 
       .detectDiskReads() 
       .detectDiskWrites() 
       .detectNetwork() // or .detectAll() for all detectable problems 
       .penaltyLog() 
       .build()); 
     StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() 
       .detectLeakedSqlLiteObjects() 
       .detectLeakedClosableObjects() 
       .penaltyLog() 
       .penaltyDeath() 
       .build()); 
    } 
    super.onCreate(); 

更多信息看:http://developer.android.com/reference/android/os/StrictMode.html