Skip to content

Instantly share code, notes, and snippets.

View ggcespia's full-sized avatar

Greg Carpenter ggcespia

View GitHub Profile
@ggcespia
ggcespia / gist1.md
Last active April 28, 2020 18:42
Create Contact Entry in Android SDK

In the 'old' days, you had to make 2 different interfaces to add contacts programmatically to Android. There was an SDK3 and SDK5 solution (yes, that long ago). Now, you may use a single API to add contact information to Android Contacts programmatically. As an FYI, I've developed Android, BREW, BlackBerry, J2ME, Palm OS, Symbian Series 40 and 60, iOS, Windows Mobile, Windows Phone and Windows 10 cross platform apps starting in 2002. The downside to the 'old' way is that you need WRITE_CONTACTS permission (and sometimes READ_CONTACTS) -these were triggered by using cr.applyBatch.

Today, you can accomplish the same task without requiring those permissions by using an Intent. The 'trick' with the intent is in the intent.putExtra(Insert.POSTAL, addr) and intent.putExtra(ContactsContract.Intents.Insert.Name, sName) values ALONG WITH using the putParcelableArrayListExtra function. Remember, you have to add the Insert.POSTAL and Insert.NAME along with the parcelable array.

Here is a samp