获取通讯录、通话记录、短信

news/2024/11/8 17:59:37/

获取通讯录:

    private ArrayList<String> getPhoneNum(Context context) {ArrayList<String> numList = new ArrayList<String>();ContentResolver cr = context.getContentResolver();Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, ContactsContract.Contacts.SORT_KEY_ALTERNATIVE+" ASC");while (cursor.moveToNext()) {String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));Cursor phone = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId, null, null);while (phone.moveToNext()) {String strPhoneNumber = phone.getString(phone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));//手机号码String strPhoneName = phone.getString(phone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));//通讯录姓名numList.add(strPhoneNumber+"--" +strPhoneName);Log.v("tag", "strPhoneNumber:" + strPhoneNumber);}phone.close();}cursor.close();return numList;}
返回结果为:13501018080--赵丽颖

所需权限:

<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />



获取最近联系人(通话记录):

    private ArrayList<String> getPhoneNum(Context context) {SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");ArrayList<String> numList = new ArrayList<String>();ContentResolver contentResolver = context.getContentResolver();Cursor cursor = null;try {cursor = contentResolver.query(CallLog.Calls.CONTENT_URI, null, null, null, CallLog.Calls.DATE + " desc");if (cursor == null)return null;while (cursor.moveToNext()) {String name = cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_NAME));String number = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER));int type = cursor.getInt(cursor.getColumnIndex(CallLog.Calls.TYPE));//1:来电(incoming calls); 2:去电(outgoing calls); 3:未接电话(missed calls)long lDate = cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DATE));long duration = cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DURATION));//通话时间/秒String news = cursor.getString(cursor.getColumnIndex(CallLog.Calls.GEOCODED_LOCATION));//返回:北京 联通numList.add(name + "-" + number + "-" + type + "-" + sdf.format(new Date(lDate)) + "-" + duration + "-" + news);}} catch (SecurityException e) {} finally {if (cursor != null) {cursor.close();}}return numList;}
返回结果:赵丽颖--13501018080--1--2016-08-15 07:45:59--120--北京 移动

需要权限:

    <uses-permission android:name="android.permission.READ_CALL_LOG" />


获取短信:

    private ArrayList<String> getPhoneNum(Context context) {Uri CONTENT_URI = Uri.parse("content://sms");ArrayList<String> numList = new ArrayList<String>();ContentResolver contentResolver = context.getContentResolver();Cursor cursor = contentResolver.query(CONTENT_URI, null, null, null, Telephony.Sms.DEFAULT_SORT_ORDER);if (cursor == null)return null;int nameColumn = cursor.getColumnIndex("person");// 联系人姓名列表序号int phoneNumberColumn = cursor.getColumnIndex("address");// 手机号int smsbodyColumn = cursor.getColumnIndex("body");// 短信内容int dateColumn = cursor.getColumnIndex("date");// 日期int typeColumn = cursor.getColumnIndex("type");// 收发类型 1表示接受 2表示发送while (cursor.moveToNext()) {String nameId = cursor.getString(nameColumn);String phoneNumber = cursor.getString(phoneNumberColumn);String smsbody = cursor.getString(smsbodyColumn);Date d = new Date(Long.parseLong(cursor.getString(dateColumn)));SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd " + "\n" + "hh:mm:ss");String date = dateFormat.format(d);String type = cursor.getString(typeColumn);String name = "未命名";Uri personUri = Uri.withAppendedPath( ContactsContract.PhoneLookup.CONTENT_FILTER_URI, phoneNumber);Cursor cur = contentResolver.query(personUri, new String[] { ContactsContract.PhoneLookup.DISPLAY_NAME }, null, null, null );if( cur.moveToFirst() ) {int nameIndex = cur.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME);name = cur.getString(nameIndex);}cur.close();numList.add(name + "-" + phoneNumber + "-" + smsbody + "-" + date + "-" + type);}cursor.close();return numList;}

返回结果:赵丽颖--+86 135 0101 8080--今晚八点万达看电影--2016-08-16 11:52:35--1


需要权限:

    <uses-permission android:name="android.permission.READ_SMS" />











http://www.ppmy.cn/news/853827.html

相关文章

API对接实战:外呼接口及通话记录推送

在白码低代码开发平台上对接七陌外呼接口,实现选择客户进行外呼,并保存通话记录的功能。 外呼接口实现 官方接口文档:http://developer.7moor.com/v2docs/dialout/ 1、对接数据查询 向七陌商务索取到七陌用户中心账号密码,在查询页面查询到三个参数 let accountId = &q…

大数据实战-callLog项目(通话记录数据分析)之数据分析

文章目录 前言mysql表结构设计db_telecom.tb_contactsdb_telecom.tb_calldb_telecom.tb_dimension_date 建表语句导入基础数据姓名手机号映射时间维度表 Meaven依赖 HBaseMaven依赖mapperreducer自定义输出OutputFormatMyRecordWriter私有属性初始化操作 设置job运行 博客链接 …

Git 常见问题

Git 常见问题 Git 常见问题分支没有跟踪信息通常错误信息提示如下&#xff1a;解决方案 Git 常见问题 分支没有跟踪信息 如果在执行 git pull 时出现这个错误信息,通常是因为当前分支没有设置跟踪信息,Git不知道应该去哪个远程分支拉取代码。 通常错误信息提示如下&#xff…

javascript提取联通个人信息和通话记录的代码

由于一些巨大的困难&#xff0c;一些后端爬虫改成了前端爬虫。 前端爬虫是只有js语言&#xff0c;后端爬虫有python java nodejs php这些语言。 前端爬虫有window.document对象&#xff0c;在浏览器端的爬虫即使是二次发送ajax&#xff0c;也不需要学后端爬虫来构造一堆请求头&…

android通话记录手机号码归属地,mui 获取手机通话记录

export default { onLoad() { this.log(); // this.msg(); // this.concat(); }, methods: { log() { // 获取通话记录 plus.android.requestPermissions( [android.permission.READ_CALL_LOG, android.permission.WRITE_CALL_LOG, android.permission.READ_SMS], function(e) …

怎么看手机计算机的记录表,教您如何查看6个月前的通话记录,包括中国联通手机!...

如何查询6个月前的呼叫历史是Internet上的常见问题,因为无论是移动,联通还是电信,您都只能查询最近6个月的呼叫历史以及呼叫顺序6个月前的查询方法?答案是肯定的,因为无论是Apple手机还是Android手机,所有通话记录都保存在手机的文件中. 通过将其导出到计算机,我们可以直…

小程序主包超1.5MB分包处理流程优化方案

"subPackages": [// 分包1 {"root": "src, // 根目录"pages": [{"path": "views/business/index", // 页面路径"name": "business_index","aliasPath": "/business/index",&…

lotus lotus-miner version 1.23.2 boostd version 1.7.4

boost Web UI settings Libp2p Peer ID 查看ID 设置 Peer ID lotus-miner actor set-peer-id <Peer ID>发布矿工 lotus-miner actor set-addrs /ip4/公网IP/tcp/端口lotus 查询报价报错 lotus client query-ask <矿工> ERROR: bls signature failed to verify…