我正在获取用户手机上所有联系信息的姓名和电话号码,但手机当前用户的姓名和图片未显示在此列表中。
Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
String trimedNumber = phoneNumber.replaceAll("[^A-Za-z0-9 ]", "").replaceAll(" ","");
if(trimedNumber.length()<10)
{
return returnValue;
}
trimedNumber = trimedNumber.substring(trimedNumber.length()-10, trimedNumber.length()-1);
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
if (!cursor.moveToFirst()) {
return returnValue;
如何获取当前用户的信息?
答案 0 :(得分:0)
按当前用户,我认为您的意思是手机的所有者。这个问题并不总能解决,但这里有一个获取所有者编号的方法:
/*
* Tries to get the user's phone number. Note that there is no guaranteed solution to this problem because the phone
* number is not physically stored on all SIM-cards, or broadcasted from the network to the phone. This is especially
* true in some countries which requires physical address verification, with number assignment only happening
* afterwards. Phone number assignment happens on the network - and can be changed without changing the SIM card
* or device (e.g. this is how porting is supported).
*/
private String getPhoneNumber() {
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String phoneNumber = telephonyManager.getLine1Number();
if (phoneNumber != null) return PhoneNumberUtils.formatNumber(phoneNumber);
else return phoneNumber;
}