I am using adb shell to delete contacts from phone. For example if I have 50 contacts, how to delete first 10?
I use this to delete one by one, is there a way to delete more contacts at once, by one command, to make process faster?
adb shell content delete --uri content://com.android.contacts/contacts/1
I am not looking to clear all contacts, but to delete some and to leave the rest of the contacts.
First, you can query all your contacts:
You can use
sedto, e.g., select the first three rows and trim them to their ids (i.e., the_idattribute:This
sedcommand says not to print anything by default (the-nswitch), but for lines 1 to 3 substitute the lines with the value of the_idand print the result (thepflag at the end of the substitution).I now tried to loop over this output and issue an
adb shell deletefor every id, but this does not work. It will only issue a command for the first id. I don’t know exactly why this is, but it must have something to do with what theadb shellcommand does.As a workaround, we can do all this directly in the adb shell. So, first execute
adb shelland then in that shell you can directly use thecontentcommand. For better readability I first save the ids in a file and then loop over its lines. Of course, it’s perfectly possible to just pipe the output of sed into the while loop.