The next zone – contacts!

So now that we have an image an OCR-ed text, we have to create a place for it to be interpreted, before the interpretation can begin. Since we are focusing on business cards for this app for now, naturally the OCR-ed text should be extracted with the relevant details and then converted into a contact. For this we need a preliminary contacts page and therefore I set out to create a form that can add my details into the Android contacts.

To do this I used several resources around the net to understand the Androids’s method of creating a Contract to tap into the Contacts Provider object. In general, I created an ArrayList of ContentProviders called ‘ops’, and added each required detail as follows:

ops.add(ContentProviderOperation
.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(
ContactsContract.Data.RAW_CONTACT_ID,
rawContactID)
.withValue(ContactsContract.Data.MIMETYPE,
StructuredName.CONTENT_ITEM_TYPE)
.withValue(StructuredName.DISPLAY_NAME,
[name value here]).build());

This helps generate a valid ArrayList to be pushed into the contacts. After that it’s just a matter of:

getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);

to add the contacts into the list. Easy-peasy 🙂

So as of now, the contacts screen is as follows, and this is what will be shown to the Prof this week on October 4th. Viva la code!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s