public void taste() {
//設默認值
SharedPreferences.Editor editor = this.getSharedPreferences("setting", 0).edit();
editor.putString("isTaste", "1");
editor.putString("customerId", "1219");
editor.putString("userAccount", "admin");
editor.putString("password", "123456");
editor.putString("accountType", "1");
editor.commit();
//要訪問的服務地址
String url = "http://www.gpsonline.cn/mobile/CheckAccount.aspx";
//POST方式
HttpPost request = new HttpPost(url);
//post參數值
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("customerId", "1219"));
params.add(new BasicNameValuePair("userAccount", "admin"));
params.add(new BasicNameValuePair("password", "123456"));
params.add(new BasicNameValuePair("accountType", "1"));
try {
//添加post參數值
HttpEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
request.setEntity(entity);
//開始訪問
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(request);
//響應爲成功
if (response.getStatusLine().getStatusCode() == 200) {
clear();
//得到返回內容
String result = EntityUtils.toString(response.getEntity());
//將返回值轉爲JSON
JSONObject json = new JSONObject(result);
JSONArray groups = json.optJSONArray("groups");
createGroupAndVehicle(groups, "0");
//打開Activity並把JSON值傳過去
Intent intent = new Intent();
intent.setClass(LoginTabActivity.this, GPSMapActivity.class);
intent.putExtra("groupId", "0");
startActivity(intent);
}
} catch (Exception e) {
Log.e("e", e.getMessage());
}
} json