我编写了这段代码,它将从应用引擎数据存储中的实体“ContactInfo”中提取所有内容并将其放入字符串中。
我的问题是如何在 android 端点中进行特定查询。例如,我只想显示实体中具有特定名称或邮政编码的项目。这是我必须将整个实体放入字符串中的内容。
package com.indeeditis;
import java.io.IOException;
import java.util.Date;
import org.json.JSONException;
import android.os.AsyncTask;
import android.content.Context;
import android.content.Intent;
import com.indeeditis.MainActivity.EndpointsTask;
import com.indeeditis.contactinfoendpoint.Contactinfoendpoint;
import com.indeeditis.contactinfoendpoint.model.CollectionResponseContactInfo;
import com.indeeditis.contactinfoendpoint.model.ContactInfo;
import com.google.api.client.extensions.android.http.AndroidHttp;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.json.jackson.JacksonFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.app.Activity;
import android.view.View.OnClickListener;
public class FinderActivity extends Activity implements OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.finder);
Button start = (Button)findViewById(R.id.button9000);
start.setOnClickListener(this);
}
public class EndpointsTask extends AsyncTask<Context, Integer, Long> {
protected Long doInBackground(Context... contexts) {
Contactinfoendpoint.Builder endpointBuilder = new Contactinfoendpoint.Builder(
AndroidHttp.newCompatibleTransport(),
new JacksonFactory(),
new HttpRequestInitializer() {
public void initialize(HttpRequest httpRequest) { }
});
Contactinfoendpoint endpoint = CloudEndpointUtils.updateBuilder(
endpointBuilder).build();
try {
String apples = endpoint.listContactInfo().execute().toString();
Log.w("myApp", apples);
} catch (IOException e) {
e.printStackTrace();
}
return (long) 0;
}
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new EndpointsTask().execute(getApplicationContext());
}
}