I am making a project in which i am using the phone contacts . In this app i am matching the number( incoming call number) with the numbers saved in contact list. I have formated the number and it is working over the phones on which the number is saved with this format +919045308261 and its not working over the phones on which the number is saved with this format +91 90 45 308261 The code that I have used is...
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);
}
}