Titanium: How to add Contact in Phone book in Andr

2019-09-03 14:24发布

I want to add Contacts in phone book. I can add contacts in iPhone properly but in documentation I got to know that in Android, phone book is ReadOnly !!!

Is there any other way to add ?

Thanks..

2条回答
走好不送
2楼-- · 2019-09-03 14:46

Solved ! I got help from this Link . We can add contacts in Android by Intent.

if (Titanium.Platform.name == 'android') 
            {
                var intent = Ti.Android.createIntent
                ({
                    action: 'com.android.contacts.action.SHOW_OR_CREATE_CONTACT',
                    data: 'mailto:'+firstName+' '+lastName
                });
                    intent.putExtra('email', email);
                    intent.putExtra('email_type', 'Work');
                    intent.putExtra('phone', mobileno);
                    intent.putExtra('phone_type', 'mobile');
                    intent.putExtra('name', firstName+' '+lastName);

                Ti.Android.currentActivity.startActivity(intent);
            }
查看更多
何必那么认真
3楼-- · 2019-09-03 14:51

Alternatively, you can create a new contact by using the createPerson method. You just have to make sure that you have the proper names and structure for each of the properties. Note that the phone numbers are arrays.

Ti.Contacts.createPerson({
    'firstName':fn.value, 
    'lastName':ln.value, 
    'phone':{'mobile':[mobile.value]}
});
查看更多
登录 后发表回答