リンク先のCodifyアプリを作成したとき、Androidに対してテストしなかったため、Androidで簡単に実行できる可能性があります。
AndroidSDKに含まれているApacheHttpClientとjson.orgを使用してこれを行う別の方法があります。
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.json.JSONException;
import org.json.JSONObject;
import android.os.AsyncTask;
public class FreebaseSearchTask extends AsyncTask<String, Void, JSONObject> {
protected JSONObject getJsonContentFromEntity(HttpEntity entity)
throws IllegalStateException, IOException, JSONException {
InputStream in = entity.getContent();
StringBuffer out = new StringBuffer();
int n = 1;
while (n > 0) {
byte[] b = new byte[4096];
n = in.read(b);
if (n > 0)
out.append(new String(b, 0, n));
}
JSONObject jObject = new JSONObject(out.toString());
return jObject;
}
@Override
protected JSONObject doInBackground(String... params) {
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
String query = params[0];
JSONObject result = null;
try {
HttpGet httpGet = new HttpGet("https://www.googleapis.com/freebase/v1/search?query=" + URLEncoder.encode(query, "utf-8"));
HttpResponse response = httpClient.execute(httpGet, localContext);
HttpEntity entity = response.getEntity();
result = getJsonContentFromEntity(entity);
} catch (Exception e) {
Log.e("error", e.getLocalizedMessage());
}
return result;
}
protected void onPostExecute(JSONObject result) {
doSomething(result);
}
}