跳转到联系人

来源:互联网 发布:如何摆脱抑郁症知乎 编辑:程序博客网 时间:2024/06/15 18:54
Intent intent = new Intent();intent.setAction(Intent.ACTION_PICK);intent.setData(ContactsContract.Contacts.CONTENT_URI);startActivityForResult(intent,CONTACT_ONRESULT);/*startActivityForResult(new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI), CONTACT_ONRESULT);*/


@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {super.onActivityResult(requestCode, resultCode, data);// 判断是否请求成功boolean isResultOk = (Activity.RESULT_OK == resultCode);// 获取请求codeswitch(requestCode){case CONTACT_ONRESULT:if(isResultOk){ContentResolver reContentResolverol = getContentResolver();Uri contactData = data.getData();Cursor cursor = managedQuery(contactData, null, null, null, null);cursor.moveToFirst();String username = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));Cursor phone = reContentResolverol.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId,null,null);while (phone.moveToNext()) {String usernumber = phone.getString(phone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));LogTools.d(TAG,"联系人:" + username + ",联系人号码" + usernumber);//TODO}}break;}}


阅读全文
0 0
原创粉丝点击