これが私のasynctaskです。onCreate()から開始したいのですが、試してみましたが、機能していません。GetChildList.execute();
次のコードに基づいて渡す必要があるパラメーターは何ですか。new String[] {my url address}
実行メソッドで渡す必要があるパラメーター。
public class GetChildList extends AsyncTask<String, Void, String> {
private String strm = "lat,longi";
private String client_id = "xxx";
private String client_secret = "xxx";
private String currentDateandTime = "20131008"; // yyyymmdd
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
DefaultHttpClient httpclient = new DefaultHttpClient();
final HttpParams httpParams = httpclient.getParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 30000);
HttpConnectionParams.setSoTimeout(httpParams, 30000);
HttpGet httppost = new HttpGet(
"https://api.foursquare.com/v2/venues/search?intent=checkin&ll="
+ strm + "&client_id=" + client_id
+ "&client_secret=" + client_secret + "&v="
+ currentDateandTime); //
try {
HttpResponse response = httpclient.execute(httppost); // response
// class
// to
// handle
// responses
jsonResult = inputStreamToString(
response.getEntity().getContent()).toString();
JSONObject object = new JSONObject(jsonResult);
} catch (ConnectTimeoutException e) {
Toast.makeText(getApplicationContext(), "No Internet",
Toast.LENGTH_LONG).show();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return jsonResult;
}
protected void onPostExecute(String Result) {
try {
Toast.makeText(getApplicationContext(),
"R E S U L T :" + jsonResult, Toast.LENGTH_LONG).show();
System.out.println(jsonResult);
// showing result
} catch (Exception E) {
Toast.makeText(getApplicationContext(),
"Error:" + E.getMessage(), Toast.LENGTH_LONG).show();
}
}
private StringBuilder inputStreamToString(InputStream is) {
String rLine = "";
StringBuilder answer = new StringBuilder();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
try {
while ((rLine = rd.readLine()) != null) {
answer.append(rLine);
}
}
catch (IOException e) {
e.printStackTrace();
}
return answer;
}
}