简体   繁体   中英

Android App sending data to Web App Script. How do I get it to stop sending Item1, Item2, etc

Here's the code in my Android program:

    @Override
    public void onClick(View v) {

        if(v==buttonAddItem){

            final ProgressDialog loading = ProgressDialog.show(this,"Adding Item","Please wait");
            final String name = editTextItemName.getText().toString().trim();
            final String brand = editTextBrand.getText().toString().trim();

            StringRequest stringRequest = new StringRequest(Request.Method.POST, "https://script.google.com/macros/s/xxxxxxxxxxxxxxxxx/exec",
                    new Response.Listener<String>() {
                        @Override
                        public void onResponse(String response) {
                            loading.dismiss();
                            Toast.makeText(MainActivity.this,response, Toast.LENGTH_LONG).show();
                            Intent intent = new Intent(getApplicationContext(),MainActivity.class);
                            startActivity(intent);
                        }
                    },
                    new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {

                        }
                    }
            ) {
                @Override
                protected Map<String, String> getParams() {
                    Map<String, String> parmas = new HashMap<>();
                    parmas.put("action","addItem");
                    parmas.put("itemName",name);
                    parmas.put("brand",brand);

                    return parmas;
                }
            };
            int socketTimeOut = 50000;
            RetryPolicy retryPolicy = new DefaultRetryPolicy(socketTimeOut, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
            stringRequest.setRetryPolicy(retryPolicy);
            RequestQueue queue = Volley.newRequestQueue(this);
            queue.add(stringRequest);

        }

    }
}

and here's my published web app:

var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/xxxxxxxxxxxxxxxxxxxxxxx/edit#gid=0");

var sheet = ss.getSheetByName('Items'); // be very careful ... it is the sheet name .. so it should match 


function doPost(e){
var action = e.parameter.action;

if(action == 'addItem'){
  return addItem(e);

}

}





function addItem(e){

var date =  new Date();

var id  =  e.parameter.doesntmatterwhatiwritehere;

var itemName = e.parameter.itemName;

var brand = e.parameter.brand;

sheet.appendRow([date,id,itemName,brand]);

   return ContentService.createTextOutput("Success").setMimeType(ContentService.MimeType.TEXT);



}

I think i've tried editing just about everything. I can't get rid of column2 posting Item2, Item3, Item4... every time I press send. Any ideas? Also, why is there no impact if I delete content form the apps script? For example, it seems like the vars don't do anything.

Nevermind. The Ap script wouldn't update unless I selected a new version during publishing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM