0

I already get all contact number (name,number ) in array and display in listview.. i already know way to insert single value into database using volley but i dont know how to insert array.

        cursor1 = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
        startManagingCursor(cursor1);

        String[] from = {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone._ID}; 

        int[] to = {android.R.id.text1, android.R.id.text2}; 

        SimpleCursorAdapter listadapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, cursor1, from, to);
        setListAdapter(listadapter);
        lv = getListView();

Volley

 @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String,String> params = new HashMap<>();
                //Adding parameters to request
                params.put("fromV", from);

I get error at from in params.put ..

John Shuk
  • 57
  • 1
  • 9

2 Answers2

0

you should pass String as second param but you are passing String[]; if you just need ArrayList then can convert String[] to List see this

Community
  • 1
  • 1
Nilesh Deokar
  • 2,975
  • 30
  • 53
0

You can do something like this for insert array

public void Insert_phone_contact(String [] contact){//Arrary of your contacts
try{

SQLiteDatabase DB = this.getWritableDatabase();
ContentValues cv = new ContentValues(); //put your contacts in the content values in the loop
for(int i=0;i<contact.length;i++){            
    cv.put(CONTACT_NAME, contact[i]);
    DB.insert(TABLE_CONTACTS, null, cv); //Insert each time for loop count            
}
DB.close(); // Now close the DB Object
}
catch(Exception ex){
Log.e("Error in phone contact insertion", ex.toString());
}
Devendra Singh
  • 2,343
  • 4
  • 26
  • 47