嗨,我有一个位置应用程序,我在 1/2 小时内将位置更新到服务器一次,它运行良好,但它使用 2.2 和 2.3 android 版本将值发布到服务器。在 3.0 及更高版本中,它正在获取 gps 坐标,而不是将值发布到服务器,有人能说出为什么会这样吗?但它运作良好,并在 2.2 和 2.3 上将值发布到服务器!
代码:
public class MainActivity extends Activity {
String Message;
DefaultHttpClient httpclient;
HttpPost httppost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GetServerResponseRawString();
}
private String GetServerResponseRawString() {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("imei", "400098890098"));
nameValuePairs.add(new BasicNameValuePair("location", "13.116,80.208"));
nameValuePairs.add(new BasicNameValuePair("latitude", "13.116"));
nameValuePairs.add(new BasicNameValuePair("longitude", "80.208"));
// nameValuePairs.add(new BasicNameValuePair("logdate", "30-04-2013"));
return GetServerResponseRawString(
"http://197.168.1.1:90/LogGeo.aspx", nameValuePairs);
}
public String GetServerResponseRawString(String str_Url,
List<NameValuePair> nvp_Parameter) {
String str_Response = "";
try {
HttpResponse response;
this.httpclient = new DefaultHttpClient();
this.httppost = new HttpPost(str_Url);
this.httppost.setEntity(new UrlEncodedFormEntity(nvp_Parameter,
HTTP.UTF_8));
response = this.httpclient.execute(this.httppost);
if (response != null
&& response.getStatusLine().getStatusCode() == 200) {
BufferedReader reader = new BufferedReader(
new InputStreamReader(
response.getEntity().getContent(), "UTF-8"));
StringBuilder builder = new StringBuilder();
for (String line = null; (line = reader.readLine()) != null;) {
builder.append(line).append("\n");
}
Message = builder.toString().split("<")[0];
str_Response = builder.toString();
return str_Response;
}
} catch (Exception e) {
String str_e = e.toString();
return str_Response;
}
return str_Response;
}
}
xml:
<uses-permission android:name="android.permission.INTERNET" />
谢谢..!