Titanium: How to add Contact in Phone book in Android?

断了今生、忘了曾经 提交于 2019-12-13 20:36:01

问题


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..


回答1:


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);
            }



回答2:


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]}
});


来源:https://stackoverflow.com/questions/9579642/titanium-how-to-add-contact-in-phone-book-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!