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

HQL : The column must appear in GROUP BY or in Select
Maven build failing for junit with test scope
Lock Methods from Object (Java)
hadoop mapreduce teragen FAIL_CONTAINER_CLEANUP
Does com.sun.tools.attach.VirtualMachine API works in JRE 1.5?
Cannot find a symbol error in java when compiling from command prompt
heap sort implementation bug, with the insert function
IntelliJ Running other class files, how do I stop this?
ClassNotFoundException with Spring Boot and ibm JDBC driver
Execute Maven/TestNG project using command line and DIFFERENT xml from command line?
Negative of UInt8
hibernate cache expiration after days
Log4j2 - Config is found, but not working correctly
Android Studio align column left - right in table row, in linear layout
Fetch result from Many to Many Relation
Eclipse: Include dependencies of other project in WAR

Categories

HOME
openlayers
pypi
deezer
fluentd
google-api-php-client
angular-material
include
grep
kalman-filter
infragistics
amazon-ecs
alpha
enterprise-library-5
fancybox
qore
android-youtube-api
apache-cayenne
n-gram
caml
karma-jasmine
opencover
pass-by-reference
icloud-api
shopware
fluentvalidation
buck
objectanimator
google-cloud-nl
madlib
r-raster
preg-match-all
functor
grails-3.1
usbserial
stringtemplate
phpfreechat
mapbox-gl
mpmediaquery
catalog
io-redirection
simplexml
jquery-bootgrid
email-templates
glew
fakeiteasy
executenonquery
filepicker
pango
elgg
feeds
font-size
windows-mobile-6.5
memory-alignment
pycaffe
google-cdn
parallel-data-warehouse
rotativa
ado.net-entity-data-model
plottable.js
gridview-sorting
gstreamer-0.10
hexdump
jfugue
django-unittest
pundit
security-testing
rgeo
cakephp-3.1
method-parameters
remobjects
web-controls
kineticjs
sorl-thumbnail
socketexception
client-side-templating
onactivityresult
ceil
uitouch
rebol3
valueconverter
valuechangelistener
flexmojos
uv-mapping
geos
listings
eclipse-memory-analyzer
type-equivalence
dice
runas
frameset
armcc
tridion-worldserver
ohm
mercurial-server
appender
gin
ncqrs
meego
nintendo-ds
simpletest

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