httpclient (phpmyadmin) not working on Android 4.0+

前端 未结 4 1056
北恋
北恋 2021-01-27 09:12

I use this code below, it works perfectly in Android 2.3.3. However, in 4.0+ it can\'t connect to database somehow. I saw some posts about you need to get it in a asynch class.

4条回答
  •  借酒劲吻你
    2021-01-27 09:58

    Ok right... After searching for few hours, making this question, then 10 minutes later, you find a solution...

    Option 1:
    I added this line:

     StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
     StrictMode.setThreadPolicy(policy);
    

    But I reccomend NOT to use option 1, this is a bad solution for real. Use option 2!
    //===========================================================================
    Option 2:

    Used this tutorial to make a proper ASyncTask: http://www.elvenware.com/charlie/development/android/SimpleHttpGetThread.html

    //===========================================================================
    Used ASyncTask as final (option 2).

提交回复
热议问题