HttpURLConnection fails on Android 4.0

后端 未结 2 987
后悔当初
后悔当初 2021-01-19 15:56

I am using this code to fetch my changelog from the net.

InputStream content = null;
           try {


               URL url = new URL(\"http://dreamhawk.b         


        
相关标签:
2条回答
  • 2021-01-19 16:24

    Well, why won't you use the WebClient? (usage: https://gist.github.com/2906703), you don't really need to mess up with the StrictMode Thread Policy. If google thought it was important to change it, who am I to disagree.

    0 讨论(0)
  • 2021-01-19 16:29

    I know in android 3.0 network connection on the main thread isnt permitted.

    StrictMode is turned on automatically. Im sure it is the same for 4.0

    To fix the issue, you must perform the network connection on a separate thread... for example, using an AsyncTask.


    Read this blog post on the subject:

    Why Ice Cream Sandwich Crashes Your App

    0 讨论(0)
提交回复
热议问题