Following this I found out how to add a contact using adb
. The only thing that's bugging me is that the user has to okay/cancel the action, because a create-contact dialog appears on the screen. What I want is for the command to automatically add the contact without waiting for the approval of the user. I've already looked through this, but couldn't find a way. Does anyone know how to do this?
-
Your Android version and device ? Is it rooted?– Firelord ♦Jan 22, 2016 at 15:48
-
I have several devices available: Nexus 5, 6.0, rooted; Samsung Note 10.1 (GT-N8010), 4.4.2, rooted; Nexus S, 4.1.2, rooted; Sony Xperia Tipo ST21i, 4.0.4, rooted. Though I'm mostly interested in adding contacts on the Note, Nexus S, and the Sony– drZaiusJan 22, 2016 at 16:05
2 Answers
For your Android 4.4.2 device the command to add a contact is (replace the Bo Lawson and #123.. to whatever you want):
adb shell am start -a android.intent.action.INSERT -t vnd.android.cursor.dir/contact -e name 'Bo Lawson' -e phone 123456789
Now to get it to save. This is Android 4.4.2 specific. Pressing back will save it. For this you need to use key events. With Android 4.4.2 it is key event 4. You are going to need to do it at least twice. Once to exit the keyboard, the other to exit and save. If required use it again to completely exit from Contacts app.
adb shell am start -a android.intent.action.INSERT -t vnd.android.cursor.dir/contact -e name 'Bo Lawson' -e phone 123456789 adb shell input keyevent 4 adb shell input keyevent 4
This worked on my rooted Samsung Galaxy Tab Pro running Android 4.4.2.
Edit: I found a post on Stack Overflow which references this command.
-
-
It actually also worked for the other devices. Too bad I didn't find the post you mentioned... Do you know if there's some kind of list of all inputs or keyevents?– drZaiusJan 23, 2016 at 12:14
-
For the current android version and if unchanged past versions. Google developers site will give you a lot of info. developer.android.com/reference/android/view/KeyEvent.html For everything then the tedious task of reading the source code. Simplified breakdown search SO, AE, individual blogs and articles. stackoverflow.com/questions/7789826/adb-shell-input-events Jan 23, 2016 at 14:15
I think there is not direct way to do that. I would recomend for you to make a simple app to insert a contact or contact list and then use it with adb. You can find an example here http://www.codeproject.com/Articles/578823/Android-Contact-Operations-Insert-Search-Delete
-
1This would sound uncool, but you can consider skipping the question from answering if you think something can't be done, unless you technically and in detail explain the reason for such. Given that this site is for end-users of Android (read: we don't expect users to have any knowledge of programming an app) the recommendation you made won't be found useful to them. :)– Firelord ♦Jan 22, 2016 at 16:46
-
Thanks for the suggestion, but I didn't want to use an app for that.– drZaiusJan 23, 2016 at 12:15