首页 > 学院 > 开发设计 > 正文

手机联系人权限 - 获取手机联系人

2019-11-08 00:38:26
字体:
来源:转载
供稿:网友
/* * 检查联系人权限 */ PRivate void getPhone() { if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) { //如果没有授权,则请求授权 ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_CONTACTS}, MY_PERMISSIONS_REQUEST_CALL_CAMERA); } else { //有授权 getPerson(ImportKinsfolkActivity.this); } } /** * 遍历手机联系人 * * @param context * @return */ public String getPerson(Context context) { String ConstrantsJson = ""; // JSONObject jsonObject = new JSONObject(); JSONArray array = new JSONArray(); Cursor cursor = context.getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null); jobjList = new ArrayList<>(); while (cursor.moveToNext()) { int indexPeopleName = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME); int indexPhoneNum = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER); String strPeopleName = cursor.getString(indexPeopleName).replace(" ", ""); String strPhoneNum = cursor.getString(indexPhoneNum).replace(" ", ""); if (Tools.isMobileNO(strPhoneNum)) { ImportKinsfolkBean bean = new ImportKinsfolkBean(); bean.name = strPeopleName; bean.phone = strPhoneNum; mList.add(bean);// JSONObject jsonObjectItem = new JSONObject();// try {// jsonObjectItem.put("Name", strPeopleName);// jsonObjectItem.put("Phone", strPhoneNum);// array.put(jsonObjectItem);// jobjList.add(jsonObjectItem);// } catch (Exception e) {// } } } if (!cursor.isClosed()) { cursor.close(); cursor = null; } ConstrantsJson = array.toString();// invite_array = array;// if(array.length() > 500) {// invite_num = Math.ceil(array.length() / 500.0);// } tv_num.setText("发现"+mNum+"条疑似亲人记录"); return ConstrantsJson; }
上一篇:FindBugs日记

下一篇:Canvas - 画布.md

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表