java


Extracting Contacts from android and saving to the database


So far I have been able to extract contacts both number and name, What I want to do is to send the data to the database via php. So far so good, instead It is sending only the last one in the array, Any suggestions as to how i can send the array and save the whole extracted contacts?
Java
String URL ="http://192.168.0.10/oap/home/SynchContacts/";
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final String name,email;
name = Name.getText().toString();
email = Email.getText().toString();
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
builder.setTitle("Server Title");
builder.setMessage(response);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog bu = builder.create();
bu.show();
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, "Error",Toast.LENGTH_SHORT).show();
error.printStackTrace();
}
}){
#Override
protected Map<String, String> getParams() throws AuthFailureError {
ContentResolver cr = getContentResolver(); //Activity/Application android.content.Context
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if(cursor.moveToFirst())
{
alContacts = new ArrayList<String>();
do
{
String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
if(Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0)
{
Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",new String[]{ id }, null);
while (pCur.moveToNext())
{
String contactNumber = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
// alContacts.add('{'+name+":"+contactNumber);
param = new HashMap<String, String>();
param.put("name[]", name);
param.put("phone[]", contactNumber);
break;
}
pCur.close();
}
} while (cursor.moveToNext()) ;
}
return param;
}
};
MySingleton.getInstance(MainActivity.this).addToRequestQueue(stringRequest);
}
});
PHP
function SynchContacts() {
$phone= $this->input->post('phone');
$name= $this->input->post('name');
for ($i=0; $i<count($phone);$i++){
$data = array(
'name'=>$name[$i],
'phone'=>$phone[$i]
);
$this->saveData('phonebook', $data);
}
}

Related Links

login using android app to a web service by supplying credentials
how to populate java object values in jsp
Summing digits of integers in an input file java error
Eclipse content assist for Gradle dependencies
JSTL.JAR can not be resolved
Why does this md5 not match [duplicate]
How to communicator between two fragment using scrollView?
Partial page rendering not working
Java conditionals in class-file (on bytecode level)
CustomTaskChange gets actually executed when called updateSQL
Creating Self Signed Certificate and KeyStore from GUI
org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
EJB EAR file migration form JBoss 6 to JBoss 7
iText create document with unequal page sizes
Array Index out of range while retrieving string from TRIE data structure?
Hibernate - NonUniqueObjectException when persist two objects

Categories

HOME
maven
log4j
proxy
mfc
rsync
binary-tree
pivotal-cloud-foundry
indesign
mouse
ssl-client-authentication
user-input
resize
moonmail
static-libraries
caml
lombok
jsdoc
scriptcs
facebook-instant-articles
lcd
crosstab
smb
centos6.5
django-storage
entitlements
assistant
elasticsearch-net
ejabberd-module
large-file-upload
gsmcomm
instant-messaging
key-value-observing
pdb
copying
usbserial
phpfreechat
windows-dev-center
textmate
azure-sql-database
http-referer
mpmediaquery
overriding
hp-ux
gulp-sourcemaps
nomethoderror
termination
forever
r-forge
mcafee
setuptools
fputcsv
persist
qcustomplot
dlna
oauth2client
associative-array
intel-fortran
wireshark-dissector
tarjans-algorithm
browser-bugs
cakephp-3.1
service-accounts
c3
coldbox
android-nested-fragment
device-manager
html-helper
starcluster
terminal-services
flexmojos
cdc
parametric-equations
osql
datareader
remember-me
memory-size
noscript
defensive-programming
windows-live-messenger
ajax-forms

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App