我正在制作一个使用电话联系人的项目。在这个应用程序中,我将号码(来电号码)与联系人列表中保存的号码匹配。我已经格式化了号码,它可以在以这种格式 +919045308261 保存号码的手机上工作,并且它不能在以这种格式 +91 90 45 308261 保存号码的手机上工作 我用过的代码是...
int hasPhoneNumber = Integer.parseInt(cursor.getString(cursor
.getColumnIndex(HAS_PHONE_NUMBER)));
if (hasPhoneNumber > 0) {
Cursor phoneCursor = contentResolver.query(
PhoneCONTENT_URI, null, Phone_CONTACT_ID + " = ?",
new String[] { contact_id }, null);
while (phoneCursor.moveToNext()) {
phoneNumber = phoneCursor.getString(phoneCursor
.getColumnIndex(NUMBER));
String formatedphn = PhoneNumberUtils.formatNumber(phoneNumber);
formatedphn = formatedphn.trim();
Log.i("formated number: ", formatedphn);
//here the number is from which the call is incoming
if(number.equals(formatedphn)){
Toast.makeText(getApplicationContext(), "got it", Toast.LENGTH_SHORT).show();
Log.i("Match occurs", "got a hit");
//Log.i("number= ", number);
String contname = phoneCursor.getString(phoneCursor
.getColumnIndex(DISPLAY_NAME));
if(!contname.equals(null)){
Toast.makeText(getApplicationContext(), contname, Toast.LENGTH_SHORT).show();
tts.speak(contname+" calling", TextToSpeech.QUEUE_FLUSH, null);
}
}