Java低级API应用引擎Android等效

时间:2013-08-21 00:29:50

标签: java android google-app-engine servlets low-level-api

我一直在关注使用java低级api与app引擎数据存储区交互的app引擎文档。我想弄清楚我需要在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);

    }
}



}

1 个答案:

答案 0 :(得分:2)

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

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