2

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
  • 3
    You need a web service which takes List of your data Commented Oct 15, 2014 at 11:57
  • androidsnippets.com/… Commented 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 class Commented Oct 15, 2014 at 12:08
  • Check how to pass ArrayList Commented Oct 15, 2014 at 12:35

3 Answers 3

1

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")); 
Sign up to request clarification or add additional context in comments.

1 Comment

thnks alot , seems it will work . should have voted this question up if had sufficient reputation :)
0

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

0

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 -> 

?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.