我需要从Contact,短信和呼叫查询中检索一个唯一的号码。
联系人,短信和电话的代码是:
从短信中检索数字:
Cursor cursor = context.getContentResolver().query(SMS_URI_ALL, null, null, null, null);
if (cursor.getCount() > 0) {
String address;
if (cursor.moveToFirst()) {
do {
address = cursor.getString(cursor.getColumnIndex("address"));
}
}
}
从通话中检索数字:
Cursor cursor = context.getContentResolver().query(CallLog.Calls.CONTENT_URI, null, where, null, null);
int number = cursor.getColumnIndex(CallLog.Calls.NUMBER);
while (cursor.moveToNext()) {
String phNumber =cursor.getString(number);
phNumber = PhoneNumberUtils.formatNumber(cursor
.getString(number));
}
从联系人中检索数字:
String where = ContactsContract.Contacts.HAS_PHONE_NUMBER + "=1";
Cursor cursor = context.getContentResolver().query(Data.CONTENT_URI,
null, where, null, null);
if (cursor.getCount() > 0) {
String number = null;
try {
while (cursor.moveToNext()) {
number = cursor.getString(cursor
.getColumnIndex(Phone.NORMALIZED_NUMBER));
}
}
}
有时我用+39检索数字,有些则没有。 我如何获得一个唯一的数字?