Android连接百度云数据库demo

时间:2022-09-22 19:21:28
new GetPosTask("GetGroupPos.php").execute();//启动异步类,括号里面为php名称


public class GetPosTask extends AsyncTask<Void, Void, List<Info>> {//Info是自定义的类
String url;
public GetPosTask(String url){//获得php文件名
this.url=url;
}
protected List<Info> doInBackground(Void... params) {//自动执行
JSONObject jsonObject = null;
//往php文件里面传参数
List<BasicNameValuePair> list = new ArrayList<BasicNameValuePair>();
list.add(new BasicNameValuePair("groupID", groupID));

try {
jsonObject = MyNetUtil.sendGetRequest(Constants.BASEURL + url,//启动
list);
if (jsonObject != null) {
JSONArray jsonArray = jsonObject.getJSONArray("GroupPos");//json数组要与php文件里面的匹配
for (int i = 0; i <= jsonArray.length(); i++) {
JSONObject jsonObject1 = (JSONObject) jsonArray.get(i);
String objectIcon = jsonObject1.getString("objectIcon");
String objectID = jsonObject1.getString("objectID");
String objectName = jsonObject1.getString("objectName");
String objectAddress = jsonObject1
.getString("objAddress");
String objectCompany = jsonObject1
.getString("objectCompany");
double infoLat = jsonObject1.getDouble("infoLat");
double infoLng = jsonObject1.getDouble("infoLng");

info_all.add(new Info(R.drawable.a01, R.drawable.maker,
objectID, objectName, objectAddress,
objectCompany, infoLat, infoLng));
}
}

} catch (Exception e) {
e.printStackTrace();
}

return info_all;
}

@Override
protected void onPostExecute(List<Info> result) {//接着上面执行完之后执行此部分,result是上面的返回值info_all
super.onPostExecute(result);
//下面写从云数据库得到数据后要进行的操作

}

}