Title: Titanium: Show and Create Contact Intent
Tags: android;android-intent;titanium;contacts;appcelerator
Question: I was trying to export contacts from my application to the native android contacts.
I found the following solution here on this site: Titanium: How to add Contact in Phone book in Android?.
And it kinda works. The intent gets started. Only problem is, that android does not recognize most of the Extras i put in. So almost every field is blank. It does not matter if I replace contactModel with a simple String, the result is the same.
So i was wondering if the keys are simply wrong, but there seems no proper documentation on appcelerator. Probably something has changed over the past years or I am just missing something. Does anybody know how to do it the right way.
Code Snippet:
if (OS_ANDROID) {
var intent = Ti.Android.createIntent({
action : 'com.android.contacts.action.SHOW_OR_CREATE_CONTACT',
data : 'mailto:' + contactModel.get('contact_first_name')  + ' ' + contactModel.get('contact_last_name')
});
intent.putExtra('email', contactModel.get('contact_email'));
intent.putExtra('email_type', 'Work');
intent.putExtra('phone', contactModel.get('contact_mobile_number'));
intent.putExtra('phone_type', 'mobile');
intent.putExtra('name', contactModel.get('contact_first_name')  + ' ' + contactModel.get('contact_last_name') );
intent.putExtra('address', addressModel.get('address_street') + ", " + addressModel.get('address_city'));
intent.putExtra('address_type', 'Work');
Ti.Android.currentActivity.startActivity(intent);
Thx in advance. :)


Here is another answer: The first parameter of putExtra() also accepts one of the constants Ti.Android.... So instead of email you would probably have to use Ti.Android.EXTRA_EMAIL.
I think you can find quite a lot in the docs, e.g. here:
EXTRA constant properties in Ti docs
EXTRA constants in Android docs
Android Intents in Ti docs
Comment for this answer: Ah, you're right. Actually i can't even find any more contacts-specific constants in the Android docs. If it really does not work with the Titanium SDK, you could think about writing and/or using a Titanium module.
Comment for this answer: Hi, unfortunately using constants (which i tried) does not have any effect. Furthermore there are only two constants in Ti.Android (Ti.Android.EXTRA_EMAIL & Ti.Android.PHONE_NUMBER) regarding Contact Intents, but the Contact Activity (Android) is able to contain more information than just those two. What do i do with the address? And so on... :D. But thx for your input.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:05/26/15', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<android><android-intent><titanium><contacts><appcelerator>', 'Title': 'Titanium: Show and Create Contact Intent', 'ViewCount': 338, 'id': 30453876, 'user_AboutMe': '', 'user_AccountId': 2453248.0, 'user_DisplayName': 'luQ', 'user_Reputation': 509.0, 'user_Views': 105.0, 'user_id': 2139007.0}}