close

之前在實作download file with Android時,

發生android.os.NetworkOnMainThreadException的問題

上網搜尋了一下後,發現是Android 3.0在網路的存取上增強的限制。

所以必須要onCreate()中加入底下的程式碼
測試過後即可解決問題

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());
arrow
arrow
    全站熱搜

    笨海豚 發表在 痞客邦 留言(2) 人氣()