I have two Android mobile devices: one v2.3 api 9 and one cellular v3.1 I want to publish an http api link for sms code. It looks like I got a honeycomb error, and the other mobile is working fine, this is the code
public void sendSMS(String phone_num, int password) { try { HttpClient hc = new DefaultHttpClient(); HttpPost post = new HttpPost("http://www.google.com/"); hc.execute(post); // I got an error here } catch(IOException e) { Log.e("error", "error"); } }
StrictMode is included in HoneyComb, you must disable it to avoid NetworkOnMainThreadException
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy);
http://developer.android.com/reference/android/os/AsyncTask.html
- Android Honeycomb. , , NetworkOnMainThreadException
NetworkOnMainThreadException
Android Honeycomb , .
, , : StrictMode$AndroidBlockGuardPolicy.onNetwork
StrictMode$AndroidBlockGuardPolicy.onNetwork
, , HTTP-.
100% !
super.onCreate protected void onCreate:
super.onCreate
protected void onCreate
! ! , ~
Async Task.So httppost . Async, http post. . http://www.vogella.com/articles/AndroidPerformance/article.html