我正在开发一个Android应用程序。我通过我的网络服务器中托管的PHP文件将我的应用程序连接到我的MySQL数据库。我使用的代码是
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
final ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
if(fid.getText().toString().trim().length() > 0 && it1.getText().toString().trim().length() > 0 && it2.getText().toString().trim().length() > 0 && it3.getText().toString().trim().length() > 0 && it4.getText().toString().trim().length() > 0 && it5.getText().toString().trim().length() > 0 && it6.getText().toString().trim().length() > 0)
{
nameValuePairs.add(new BasicNameValuePair("item1",item1));
nameValuePairs.add(new BasicNameValuePair("item2",item2));
nameValuePairs.add(new BasicNameValuePair("item3",item3));
nameValuePairs.add(new BasicNameValuePair("item4",item4));
nameValuePairs.add(new BasicNameValuePair("item5",item5));
nameValuePairs.add(new BasicNameValuePair("item6",item6));
nameValuePairs.add(new BasicNameValuePair("fr", fr));
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://applicationdownloader.net46.net/walcliff/newitems.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
//convert response to string
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
我面临的问题是
1.应用程序未运行版本2.2 ie.Froyo,我检查了错误,发现StrictMode在8级以下的API级别中不可用。
2.应用程序运行正常,数据库在API级别大于8时更新。
我评论了Strictmode并在2.2版本的手机中进行了调试,但我得到了Exception。
请建议我使用strictmode等效,因为这个应用程序对于所有设备都应该是SCALABLE。