I am new to android and got entangle in problem. what i want is to pass an array object or say an arraylist to a php page so that the same can be inserted into the mysql database.To be more precise i would like to develop an app to sync my contacts with phone numbers to my own server. thanks in advance.
4
-
3You need a web service which takes List of your dataSweetWisher ツ– SweetWisher ツ2014-10-15 11:57:00 +00:00Commented Oct 15, 2014 at 11:57
-
androidsnippets.com/…Steve– Steve2014-10-15 11:58:40 +00:00Commented Oct 15, 2014 at 11:58
-
thnks for the link steve, but example at androidsnippets shows to enter only the single key and value pair what i want is to wrap the whole list of contacts name and number into an arraylist and then this arraylist to be passed to namevaluepair classMohit Wadhwani– Mohit Wadhwani2014-10-15 12:08:22 +00:00Commented Oct 15, 2014 at 12:08
-
Check how to pass ArrayListSweetWisher ツ– SweetWisher ツ2014-10-15 12:35:14 +00:00Commented Oct 15, 2014 at 12:35
Add a comment
|
3 Answers
Try like this.
Map<String,Object> productimages = new HashMap<String, Object>();
List<String> datas = new ArrayList<String>();
datas.add("image");
datas.add("small_image");
datas.add("thumbnail");
productimages.put("types",datas);
If your using nemevalue pair use like this.
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("colors[]","red"));
nameValuePairs.add(new BasicNameValuePair("colors[]","white"));
nameValuePairs.add(new BasicNameValuePair("colors[]","black"));
nameValuePairs.add(new BasicNameValuePair("colors[]","green"));
1 Comment
Mohit Wadhwani
thnks alot , seems it will work . should have voted this question up if had sufficient reputation :)
You should be using an API for ex.Rest API. This API will grant the information from your app by an POST action (from you're android app). (transfer data-objects like an array with JSON) Php can decode the JSON and you analyze you're array in php. You can now send specific data into your tables using MYSQL, PDO,..
If the data you transfer needs to be protected, you should use SSL encryption on you're api acces url
Comments
Try this
ArrayList <NameValuePair> postparametersSend = new ArrayList <NameValuePair> ();
//This is your file php
String URL = "www.yourserver.com/file.php";
postparameters2send.add (new BasicNameValuePair ("param1", nameParam1));
postparameters2send.add (new BasicNameValuePair ("param2", nameParam2));
postparameters2send.add (new BasicNameValuePair ("param3", nameParam3));
// perform a request and response obtenes JSON array
JSONArray jdata = con.getserverdata (postparametersSend, URL);
//since we are working locally on return will almost immediately
//To give a little realism we say that the process is stopped for a few seconds to
//Observe progressdialog
// We can remove if we
// if what we got is not null
if (jdata! = null && jdata.length ()> 0) {
JSONObject json_data; // create a JSON object
try {
jdata.getJSONObject json_data = (0); // read the first segment in our case the only
System.out.println (json_data);
logstatus = json_data.getInt ("logstatus"); // access the value
Log.e ("LoginStatus", "logstatus =" + logstatus) // show by log we obtained
} Catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace ();
}
// validate the value obtained
if (logstatus == 0) {// [{"logstatus": "0"}]
Log.e ("logStatus", "invalid");
return false;
}
else {// [{"logstatus": "1"}]
Log.e ("logStatus", "valid");
return true;
}
//} else {invalid json obtained WEB verify part.
Log.e ("JSON", "ERROR");
return false;
}
To make the variables you should put this in the php file
<? php
$nameParam1 = $_POST ["nameParam1"];
$nameParam2 = $_POST ["nameParam2"];
$nameParam3 = $_POST ["nameParam3"];
<- Put your code here ->
?>