使用ListView控件呈现
这个根据<第一行代码学习来的> 部分改进
现在的手机读取通讯录都是需要权限的。
布局文件
activity_main

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"><ListViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/contest_view"/></LinearLayout></androidx.constraintlayout.widget.ConstraintLayout>

mainfest文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.example.contactstest"><uses-permission android:name="android.permission.READ_CONTACTS"/><applicationandroid:allowBackup="true"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:roundIcon="@mipmap/ic_launcher_round"android:supportsRtl="true"android:theme="@style/Theme.ContactsTest"><activityandroid:name=".MainActivity"android:exported="true"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity></application></manifest>

main代码:

package com.example.contactstest;import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;import java.util.ArrayList;
import java.util.List;public class MainActivity extends Activity {ListView contactsView;ArrayAdapter<String> adapter;List<String> contactsList=new ArrayList<String>();@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);contactsView=(ListView) findViewById(R.id.contest_view);adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,contactsList);contactsView.setAdapter(adapter);//这个地方就是请求权限if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS)!= PackageManager.PERMISSION_GRANTED) {ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.READ_CONTACTS},1);} else {readContacts();}//readContacts();}private void readContacts(){Cursor cursor=null;try {cursor =getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,null,null,null);while (cursor.moveToNext()) {int i_name=cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);String displayName = cursor.getString(i_name);int i_number=cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);String number = cursor.getString(i_number);contactsList.add(displayName + "\n" + number);}}catch (Exception e){e.printStackTrace();}finally {if (cursor!=null){cursor.close();}}}
}

效果:

Android读取手机通讯录相关推荐

  1. java获取手机通讯录权限_Android读取手机通讯录联系人到自己项目

    本文实例为大家分享了Android读取手机通讯录联系人到项目的具体代码,供大家参考,具体内容如下 一.主界面代码如下: android:layout_width="match_parent& ...

  2. android+读取电话权限,【uniapp】 读取手机通讯录权限

    现在很多APP,市场需求都需要读取我们手机上的相关权限,例如WX要读取通讯录,相册,照相机等权限,其他APP亦如此 但是在获得这些权限之前我们首先需要征得用户的统一之后才能读取 官方讲解: https ...

  3. 【uniapp】 读取手机通讯录权限

    现在很多APP,市场需求都需要读取我们手机上的相关权限,例如WX要读取通讯录,相册,照相机等权限,其他APP亦如此 但是在获得这些权限之前我们首先需要征得用户的统一之后才能读取 官方讲解: https ...

  4. android获取手机通讯录联系人

    android获取手机通讯录联系人信息 private void getPhoneContacts() { ContentResolver resolver = this.getContentReso ...

  5. 最快速读取手机通讯录中联系人信息

    作为一名Android开发,读写手机通讯录的操作人人都会,但是有没有遇到通讯录存在好几百条联系人信息时候读取的速度会明显变慢呢?本文就是介绍解决办法,我总结出了以下几种办法 提供参考: 一.线程 有A ...

  6. Android系统手机通讯录

    基于Android系统手机通讯录软件的设计和开发 自google于2005年收买Android公司,Android商场有了很大的遍及,加上无线网络的敏捷开展,手机网速有了很大的提高,为智能手机的开展供 ...

  7. android 通过手机号码查询联系人,android获取手机通讯录联系人

    android获取手机通讯录联系人信息 private void getPhoneContacts() { ContentResolver resolver = this.getContentReso ...

  8. 基于 Android 系统手机通讯录管理软件【100010322】

    基于 Android 系统手机通讯录管理软件 第一章 绪论 1.1 项目研究背景 经过多年的发展,移动终端不再仅是通讯网络的终端,还将成为互联网的终端.因此,移动终端的应用软件和需要的服务将会有很大的 ...

  9. android sim卡联系人存储格式,Android获取手机通讯录、sim卡联系人及调用拨号界面方法...

    android获取手机通讯录联系人信息 private void getPhoneContacts() { ContentResolver resolver = this.getContentReso ...

  10. Android个人手机通讯录开发详解

    一.Android 个人手机通讯录开发 数据存储:SQLite 数据库 开发工具:Android Studio 二.Phone Module 简介 界面展示 文件结构简单分析 三.个人手机通讯录代码实 ...

最新文章

  1. Android自定义View基本步骤
  2. 设计模式---原型模式(Prototype Pattern)
  3. Shader 中的随机与噪声
  4. 恢复SQL Server被误删除的数据
  5. Linux安装Redis完整步骤
  6. android staticlayout使用讲解,可实现文本绘制换行处理
  7. listary什么意思_listary使用心得
  8. Java线程通信之等待/通知
  9. android 全局对话框6,[Android][Framework]从全局AlertDialog聊聊WindowManager
  10. linux path_lookup,Linux虚拟文件系统(4)-- 路径名查找
  11. TP-LINK 无线路由器桥接步骤
  12. java打印两个小人_Swing多线程实现奔跑的小人动画代码实现 | 彬菌
  13. lae界面开发工具入门之介绍九--简单逻辑篇
  14. Java解压压缩加密文件zip
  15. Hash 表详解(哈希表)
  16. 海康大华宇视等等安防监控摄像头转成WebRTC流实现Web浏览器超低延迟无插件直播新方案
  17. Jetson AGX Xavier刷机+安装opencv+使用TensorRT加速推理yolo全过程+心路历程
  18. Chrome浏览器主页被恶意篡改解决方案
  19. 常见DOS命令及自定义DOS命令
  20. 【CGAL】表面细化

热门文章

  1. /dev/null空字符设备文件
  2. printf linux 头文件,printf()函数 [转]linux调用动态库so文件(2)
  3. android optionmenu 动态显示,android – 如何在onCreateOptionsMenu中动态更改菜单
  4. zynq processing system 参数设置_【正点原子FPGA连载】第六章自定义IP核-呼吸灯实验-领航者 ZYNQ 之嵌入式开发指南...
  5. excel下拉速度太慢_全靠这些Excel、Word一键录入技巧,我才能用10分钟完成3小时工作...
  6. matlab四宫格画图_科学网—Matlab画图(一):生成高质量的供发表和展示用的图 - 周建锋的博文...
  7. dom控制html元素编号,JavaScript DOM对象控制HTML元素详解
  8. oracle erase,Arc SDE forOracle实现erase空间分析计算
  9. 简单链表实现增删改查(内部类+递归)
  10. linux lsb版本错误,CentOS中-bash: lsb_release: command not found错误的解决方法