Android获取手机通讯录、sim卡联系人及调用拨号界面方法
作者:junjie 时间:2021-07-02 00:41:07
android获取手机通讯录联系人信息
private void getPhoneContacts() {
ContentResolver resolver = this.getContentResolver();
// 获取手机联系人
Cursor phoneCursor = resolver.query(Phone.CONTENT_URI,
new String[] { Phone.CONTACT_ID, Phone.DISPLAY_NAME,
Phone.NUMBER },
Phone.DISPLAY_NAME + "=?" + " AND " + Phone.TYPE + "='"
+ Phone.TYPE_MOBILE + "'", new String[] { name }, null);
if (phoneCursor != null) {
while (phoneCursor.moveToNext()) {
String number = phoneCursor.getString(2);
// 当手机号码为空的或者为空字段 跳过当前循环
if (TextUtils.isEmpty(phoneNumber))
continue;
// 得到联系人名称
String username = phoneCursor.getString(1);
mContactsName.add(contactName);
mContactsNumber.add(phoneNumber);
}
phoneCursor.close();
}
}
获得手机sim卡联系人信息
sim卡和手机本人 获取的方式类似 只是url有点不一样 ,须要注意的一点是 sim卡 是没有联系人头像的。
private void getSIMContacts() {
ContentResolver resolver = mContext.getContentResolver();
// 获取Sims卡联系人
Uri uri = Uri.parse("content://icc/adn");
Cursor phoneCursor = resolver.query(uri,
new String[] { Phone.CONTACT_ID, Phone.DISPLAY_NAME,
Phone.NUMBER },
Phone.DISPLAY_NAME + "=?" + " AND " + Phone.TYPE + "='"
+ Phone.TYPE_MOBILE + "'", new String[] { name }, null);
if (phoneCursor != null) {
while (phoneCursor.moveToNext()) {
String number = phoneCursor.getString(2);
// 当手机号码为空的或者为空字段 跳过当前循环
if (TextUtils.isEmpty(phoneNumber))
continue;
// 得到联系人名称
String username = phoneCursor.getString(1);
mContactsName.add(contactName);
mContactsNumber.add(phoneNumber);
}
phoneCursor.close();
}
}
调用系统拨打电话的界面 ,代码如下。
tel:电话号码
//调用系统方法拨打电话
Intent dialIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + mContactsNumber.get(position)));
startActivity(dialIntent);
最后,千万别忘记在AndroidManifest.xml文件中添加权限,否则运行程序是报错!
<!-- 读取联系人权限 -->
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<!-- 拨打电话权限 -->
<uses-permission android:name="android.permission.CALL_PHONE"/>
标签:Android,手机,通讯录,联系人,sim卡,拨号界面
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android实现文字垂直滚动、纵向走马灯效果的实现方式汇总
2023-03-02 22:24:54
![](https://img.aspxhome.com/file/2023/8/93298_0s.gif)
java编程实现优先队列的二叉堆代码分享
2022-11-13 15:32:13
RxJava+Retrofit+Mvp实现购物车
2022-03-22 16:24:48
![](https://img.aspxhome.com/file/2023/7/64957_0s.gif)
C#四种计时器Timer的区别和用法
2021-10-12 01:31:14
Springboot自带定时任务实现动态配置Cron参数方式
2023-11-10 10:21:31
![](https://img.aspxhome.com/file/2023/1/59161_0s.jpg)
深入分析C# Task
2022-10-24 12:39:00
MyEclipse2018中安装Mybatis generator插件的实现步骤
2022-02-17 03:47:37
![](https://img.aspxhome.com/file/2023/9/63649_0s.png)
关于mybatis3中@SelectProvider的使用问题
2021-11-20 17:03:19
Java实战在线选课系统的实现流程
2022-12-19 10:34:30
![](https://img.aspxhome.com/file/2023/4/86724_0s.png)
java8 集合 多字段 分组 统计个数代码
2022-12-07 21:03:34
![](https://img.aspxhome.com/file/2023/5/72325_0s.jpg)
C# PropertyInfo类案例详解
2021-12-11 16:47:45
Java Socket实现单线程通信的方法示例
2022-04-22 15:43:02
Java实现十进制与二进制互转的示例详解
2022-04-02 07:40:56
C语言数据结构实现银行模拟
2023-04-16 17:25:49
![](https://img.aspxhome.com/file/2023/7/109777_0s.jpg)
C#访问SqlServer设置链接超时的方法
2022-11-19 17:43:21
Android游戏开发学习②焰火绽放效果实现方法
2023-10-26 08:54:53
![](https://img.aspxhome.com/file/2023/0/106830_0s.png)
使用Java实现三种等级的扫雷游戏(完整版)
2023-05-10 07:34:17
![](https://img.aspxhome.com/file/2023/8/83028_0s.png)
springboot 实战:异常与重定向问题
2022-03-06 15:44:54
![](https://img.aspxhome.com/file/2023/8/66048_0s.png)
SpringBoot 导出数据生成excel文件返回方式
2023-09-01 11:29:27
![](https://img.aspxhome.com/file/2023/0/92670_0s.jpg)
IDEA项目maven project没有出现plugins和Dependencies问题
2021-08-08 10:59:53
![](https://img.aspxhome.com/file/2023/1/61871_0s.png)