Android – error executing HTTP post in cell
•
Android
I have two Android mobile devices, a v2.3 API 9 and a v3.1 cell. I want to publish the HTTP API link of SMS code. It becomes that I have an error in the cell and other mobile devices work normally. 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");
}
}
resolvent:
To enable strictmode in honeycomb, you must disable it to avoid networkonmainthreadexception
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
However, asynctask is not recommended. Here you can find an example:
http://developer.android.com/reference/android/os/AsyncTask.html
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码