Can you please let me know if there is any adb command that can be used to find total number of contacts on device. -thanks in advance, Manju
4 Answers
this does not require root and sqlite
:
adb shell content query --uri content://contacts/phones/ --projection display_name:number:notes # google contacts?
adb shell content query --uri content://com.android.contacts/data --projection display_name:data1:data4:contact_id
-
1I´m getting permission denial with that commands, "accessing provider:com.android.contactsjava.lang.SecurityException: Permission Denial: Do not have permission in call getContentProviderExternal() from pid=12044, uid=10101"– xanexptJun 10, 2020 at 21:03
-
Yet more compact: $ adb shell content query --uri content://contacts/phones/ --projection display_name:number | cut -f 3- -d " "– dzmantoAug 28, 2021 at 10:47
There are a few adb
commands that appear to work (as of on Android 10).
List the people in the contact list
adb shell content query --uri content://contacts/people/
Count people in contact list
Assuming you have a bash shell (Linux, OSX, or Windows Subsystem for Linux), you can pipe the output of those commands to wc -l
to get the count.
adb shell content query --uri content://contacts/people/ | wc -l
Other interesting commands include:
List the phone numbers
adb shell content query --uri content://contacts/phones/
List the groups
adb shell content query --uri content://contacts/groups/
List group membership
adb shell content query --uri content://contacts/groupmembership/
List organizations
adb shell content query --uri content://contacts/organizations/
You can try the following code:
Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null,null, null,null);
while (cursor.moveToNext()) {
listName.add(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));
listContactId.add(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)));
if (Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
Cursor pCur = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)),null, null);
while (pCur.moveToNext()) {
listMobileNo.add(pCur.getString(pCur.getColumnIndex("DATA1")));
}
pCur.close();
} else
listMobileNo.add("");
}
update
adb pull /data/data/com.android.providers.contacts/databases/contacts2.db <PATH TO PASTE THE DATABASE>
after retreiving the DB use SQLite Browser to open it
-
is there any adb command available to get count of contacts on android device ?– ManjuSep 19, 2014 at 6:48
-
1phone not rooted !! permission denied !! c:\>adb pull /data/data/com.android.providers.contacts/databases/contacts2.db . failed to copy '/data/data/com.android.providers.contacts/databases/contacts2.db' to './contacts2.db': Permission denied– ManjuSep 19, 2014 at 6:59
-
To count all contacts on the device:
adb shell content query --uri content://com.android.contacts/contacts | wc -l