[英]Android: How can I get device hardware information with adb command?
[英]Android adb command to get total contacts on device
您能否让我知道是否有任何 adb 命令可用于查找设备上的联系人总数。 - 提前致谢,Manju
这不需要 root 和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
有一些adb
命令似乎可以工作(从 Android 10 开始)。
adb shell content query --uri content://contacts/people/
假设您有一个 bash shell(Linux、OSX 或适用于 Linux 的 Windows 子系统),您可以将这些命令的输出通过管道传输到wc -l
以获取计数。
adb shell content query --uri content://contacts/people/ | wc -l
其他有趣的命令包括:
adb shell content query --uri content://contacts/phones/
adb shell content query --uri content://contacts/groups/
adb shell content query --uri content://contacts/groupmembership/
adb shell content query --uri content://contacts/organizations/
您可以尝试以下代码:
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("");
}
adb pull /data/data/com.android.providers.contacts/databases/contacts2.db <PATH TO PASTE THE DATABASE>
检索数据库后使用 SQLite 浏览器打开它
要计算设备上的所有联系人:
adb shell content query --uri content://com.android.contacts/contacts | wc -l
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.