访问通讯录并返回号码(多个号码可以选择)
来源:互联网 发布:无间道3电影解析知乎 编辑:程序博客网 时间:2024/04/30 08:52
Intent i = new Intent(Intent.ACTION_PICK, android.provider.ContactsContract.Contacts.CONTENT_URI);startActivityForResult(i, 1);
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { Uri contactData = data.getData(); Cursor cursor = managedQuery(contactData, null, null, null, null); cursor.moveToFirst(); String num = this.getContactPhone(cursor); } } private String getContactPhone(Cursor cursor) { int phoneColumn = cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER); int phoneNum = cursor.getInt(phoneColumn); final List<String> result = new ArrayList<>(); position = 0; if (phoneNum > 0) { int idColumn = cursor.getColumnIndex(ContactsContract.Contacts._ID);// 获得联系人的ID号 String contactId = cursor.getString(idColumn); // 获得联系人电话的cursor Cursor phone = getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=" + contactId, null, null); if (phone.moveToFirst()) { for (; !phone.isAfterLast(); phone.moveToNext()) { int index = phone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER); int typeindex = phone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE); String phoneNumber = phone.getString(index); result.add(phoneNumber); } if (!phone.isClosed()) { phone.close(); } } } if (result.size() > 1) {//如果号码多于2个,则弹出对话框让他选择 AlertDialog.Builder builder = new AlertDialog.Builder(this); int size = result.size(); builder.setTitle("请选择一个号码").setItems(result.toArray(new String[size]), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { position = which; } }).create().show(); } return result.get(position); }
1 0
- 访问通讯录并返回号码(多个号码可以选择)
- android调用系统通讯录,并返回联系人号码和称呼
- Android调用系统通讯录,并返回联系人号码和称呼
- android从通讯录中选择联系人并读取号码
- 通讯录号码的批量操作,将号码进行分类返回
- iOS 通讯录操作 删除联系人 以及联系人多个号码 删除其中一个号码
- iOS 通讯录操作 删除联系人 以及联系人多个号码 如何删除其中一个号码
- Android通讯录添加号码
- 号码
- 号码
- 号码!
- 号码
- IOS通讯录选取某个号码
- 腾讯—通讯录中每条记录存放着通讯者与其所使用的号码,号码与使用者之间是多对多关系,找出使用最多的号码并输出使用者
- 多个前缀号码的提取方法。
- [出场顺序号码随机抽取并公开展示、并行随机抽取多个题目号码,并公开展示]软件原型设计
- 通讯录获取和带号码分区排序
- iPhone通讯录号码不见了怎么恢复
- 数学电子书下载
- 线程局部存储
- kpush源码解析---android端
- Tips to Optimize Your SQL Statements - Part 2
- 【HDU】5227 Tom and game【快速求gcd值+点分治】
- 访问通讯录并返回号码(多个号码可以选择)
- [JSP]JSP内置对象(1)
- Matlab中使用sub2ind函数访问数据
- ER-Studio的五种关系说明 .
- ORA-02049: 超时: 分布式事务处理等待锁诊断
- android library工程项目之间的相互引用出现的问题
- C++ vector容器类型
- android 事件处理
- 检测Android是否连接WIFI