获取Titanium中的电话号码(android) [英] Get Phone Number(android) in Titanium

查看:79
本文介绍了获取Titanium中的电话号码(android)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取android中的电话号码?

How can I get phone number in android?

示例代码:

var contacts = Titanium.Contacts.getAllPeople();
Titanium.API.log(contacts[0].phone['mobile'][0]); //in iOS, returns "01012345678" fine :)
Titanium.API.log(contacts[0].phone['mobile'][0]); //in Android, returns ""  :(
Titanium.API.log(contacts[0].fullName); //in Android & iOS, returns "test Name" fine :)
Titanium.API.log(contacts[0].phone); //in Android, returns "" :(

推荐答案

尝试以下代码,与我合作

Try the following code, It worked with me

//Getting all the contacts
var people = Ti.Contacts.getAllPeople();

//Getting the total number of contacts
var totalContacts = people.length;
//Checking whether the contact list is empty or not
if( totalContacts > 0 )
{
    for( var index = 0; index < totalContacts; index++ )
    {
       //Holding the details of a single contact
       var person = people[index];
      Ti.API.info("Mobile -> " + person['phone'].mobile + " home-> " + person['phone'].home);
    }
}

请注意,您的手机应在移动和家庭选项中具有联系电话.我从Android模拟器中添加了一个屏幕截图.只是尝试给出这样的数字

note that your phone should have contact number in mobile and home options. I've added a screen shot from my android emulator. Just try giving numbers like this

这篇关于获取Titanium中的电话号码(android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆