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

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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());
}

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.