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

查看:29
本文介绍了在 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天全站免登陆