0

我一直在关注有关使用 java 低级 api 与应用引擎数据存储进行交互的应用引擎文档。我试图弄清楚我需要哪些导入和语法更改才能在 android 中进行这项工作。我在下面混合了android和java代码。java put() 和 get() 方法的正确 android 语法是什么?

 package com.direction.investor.bcms;

 //PSUEDO CODE

 //JAVA IMPORTS. ANDROID EQUIVALENTS?

 //import com.google.appengine.api.datastore.DatastoreService;
 //import com.google.appengine.api.datastore.DatastoreServiceFactory;
 //import com.google.appengine.api.datastore.Entity;
//import com.google.appengine.api.datastore.Key;
//import com.google.appengine.api.datastore.KeyFactory;
//import com.google.appengine.api.users.User;
//import com.google.appengine.api.users.UserService;
//import com.google.appengine.api.users.UserServiceFactory;
//import java.io.IOException;
//import java.util.Date;

//import javax.servlet.http.HttpServlet;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;





 //import java.io.IOException;
 //import java.util.Date;

 //import javax.servlet.http.HttpServlet;
 //import javax.servlet.http.HttpServletRequest;
 //import javax.servlet.http.HttpServletResponse;



 import android.widget.EditText;

 public class ContactInfo {

public void onSubmitDataButtonPress{

//CONVERT INPUT TO STRING

EditText streetName;

streetName = (EditText) findViewById (R.id.streetNameEdit);

   String streetInfo = streetName.getText().toString();

  EditText zipCode;

   zipCode = (EditText) findViewById (R.id.zipCodeEdit);

  String zipInfo = zipCode.getText().toString();

}

  // PLACE STRINGS ON DATASTORE

public class ContactInfoServlet extends HttpServlet {
    public void doPost(HttpServletRequest req, HttpServletResponse resp)
                throws IOException {




        Key ContactInfoKey = KeyFactory.createKey("Contact", contactkey);
        String street = req.getParameter("streetInfo");
        String zip = req.getParameter("zipInfo");
        Date date = new Date();
        Entity contacts = new Entity("UserContactInfo", contactkey);

        contacts.setProperty("date", date);
        contacts.setProperty("street", street);
        greeting.setProperty("zip", zip);

        DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
        datastore.put(contacts);

    }
}



}
4

1 回答 1

2

我认为您不了解 App Engine 架构。低级 API 在 App Engine 实例上运行。你不能在安卓上使用它。时期。

如果您希望您的 android 应用程序与 App Engine 交互,它必须通过 HTTP 接口。您可以在 App Engine 上编写自己的处理程序,或者使用更少的代码使用 App Engine Endpoints,它本质上会生成 HTTP 请求处理程序以与您的模型进行交互。

于 2013-08-21T03:59:33.413 回答