从Android应用将数据发布到Google表单

时间:2016-08-01 07:53:12

标签: android

主要活动中有2个文本框,ed1ed2以及保存按钮。

final EditText ed1 = (EditText)findViewById(R.id.location_address);
final EditText ed2 = (EditText)findViewById(R.id.workername);

public void postData() {

    String fullUrl = "https://docs.google.com/forms/d/e/1FAIpQLSe5WZB-e95xrx3ZbwiOWtJx3wEuT-fJw/formResponse";
    HttpRequest mReq = new HttpRequest();

    String data = "entry.748835646=" + URLEncoder.encode(location) + "&" + 
                  "entry.481985278=" + URLEncoder.encode(name);
    String response = mReq.sendPost(fullUrl, data);
    Log.i(myTag, response);
} 

我没有得到为String数据上面的2个edittexts写的​​内容。

如何编写ed1ed2的代码,以便在用户输入ed1ed1后,点击“保存”按钮,数据会保存到Google形成? (即执行postData方法)

2 个答案:

答案 0 :(得分:1)

public void postData() {

String fullUrl = "https://docs.google.com/forms/d/e/1FAIpQLSe5WZB-e95xrx3ZbwiOWtJx3wEuT-fJw/formResponse";
HttpRequest mReq = new HttpRequest();

String data = "entry.748835646=" + URLEncoder.encode(ed1.getText().toString()) + "&" + 
              "entry.481985278=" + URLEncoder.encode(ed2.getText().toString());
String response = mReq.sendPost(fullUrl, data);
Log.i(myTag, response);
} 

答案 1 :(得分:0)

我自己解决了这个问题:

修改后的postData()方法如下: -

public void postData(){

    String fullUrl = "https://docs.google.com/forms/d/e/1FAIpQLSe5WZbIwv6m5uqf2Z73Uh7B-e95xrx3ZbEuT-fJw/formResponse";
    HttpRequest mReq = new HttpRequest();

    final EditText ed1 = (EditText)findViewById(R.id.location_address);
    final EditText ed2 = (EditText)findViewById(R.id.workername);

    location=ed1.getText().toString();
    name=ed2.getText().toString();


    String data = "entry.748835646=" + URLEncoder.encode(location) + "&" + 
                  "entry.481985278=" + URLEncoder.encode(name);
    String response = mReq.sendPost(fullUrl, data);
    Log.i(myTag, response);
}