
每个人都知道Android应用程序在手机上更受欢迎,我们如何使用Android从SIM卡获取联系人?徐州北大青玉鸟老师具有需要同步本地联系信息的功能. 它主要从SIM卡和android中获取SIM卡以获取联系人. 由于SIM卡的容量有限,因此仅存储联系人的姓名和电话号码. 下面是徐州北大青鸟老师提供的密码,有兴趣的同学可以参考.
私有静态最终int NAME_COLUMN = 0;
私有静态最终整数NUMBER_COLUMN = 1;
private static final String SURI =“ content: // icc / adn”;
private Context context = null;
私有ContentResolver解析器= null;
私人TelephonyManager telMgr = null;
公共SimHelper(上下文上下文)
{
this.context =上下文;
resolver = context.getContentResolver();
}
公用TelephonyManager getTelephonyManager()
{
如果(telMgr == null)
{
telMgr =(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
}

返回telMgr;
}
public int getSimCardState()
{
返回getTelephonyManager(). getSimState();
}
公共列表
{
列表
Uri uri = Uri.parse(SURI);
光标游标= resolver.query(uri,null安卓sim卡联系人导出安卓sim卡联系人导出,null,null,null);
对于(cursor.moveToFirst();! cursor.isAfterLast(); cursor.moveToNext())
{
ContactInfo contacInfo =新的ContactInfo();
最终NamePhoneTypePair名称PhoneTypePair =新的NamePhoneTypePair(
cursor.getString(NAME_COLUMN));
最终字符串名称= namePhoneTypePair.name;
final int phoneType = namePhoneTypePair.phoneType;

最终字符串phoneNumber = cursor.getString(NUMBER_COLUMN);
setPhoneInfo(contacInfo,phoneType,phoneNumber);
contacInfo.setName(名称);
simContactInfoList.add(contacInfo);
}
cursor.close();
返回simContactInfoList;
}
private void setPhoneInfo(ContactInfo contactInfo,int phoneType,
字符串phoneNumber)
{
电话=新电话();
phone.setType(PhoneType.valueOf(phoneType));
phone.setNumber(phoneNumber);
contactInfo.getPhones(). 添加(电话);
}
私有静态类NamePhoneTypePair
{

最终字符串名称;
final int phoneType;
公用名PhoneTypePair(字符串nameWithPhoneType)
{
///在表示类型的名称末尾查找/ W / H / M或/ O
int nameLen = nameWithPhoneType.length();
如果(nameLen-2> = 0
&& nameWithPhoneType.charAt(nameLen-2)=='/')
{
char c = Character.toUpperCase(nameWithPhoneType.charAt(nameLen-1));
如果(c =='W')
{
phoneType = PhoneType.Company.getPhoneType();
}
否则,如果(c =='M'|| c =='O')
{
phoneType = PhoneType.Mobile.getPhoneType();
}

否则(c =='H')
{
phoneType = PhoneType.Home.getPhoneType();
}
其他
{
phoneType = PhoneType.Other.getPhoneType();
}
name = nameWithPhoneType.substring(0,nameLen-2);
}
其他
{
phoneType = PhoneType.Other.getPhoneType();
name = nameWithPhoneType;
}
}
}
我在Android应用程序中看到了Phone的源代码. 看来我可以获得联系电话的类型. 徐州北大青鸟的技术老师可以做到. 如果您有兴趣,可以参加北大青鸟的课程. 您无法想到很多令人兴奋的内容. !!
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/sanxing/article-154280-1.html
被警告后也就撤出了
饮料口味不错