Reputation: 1881
I am using the below code to know if any contact exists with a number in android native contacts
public boolean contactExists(Context context, String number) {
/// number is the phone number
Uri lookupUri = Uri.withAppendedPath(
PhoneLookup.CONTENT_FILTER_URI,
Uri.encode(number));
String[] mPhoneNumberProjection = { PhoneLookup._ID, PhoneLookup.NUMBER, PhoneLookup.DISPLAY_NAME };
Cursor cur = context.getContentResolver().query(lookupUri,mPhoneNumberProjection, null, null, null);
try {
if (cur.moveToFirst()) {
return true;
}
} finally {
if (cur != null)
cur.close();
}
return false;
}
my problem is that if i get a number with country code added.
so,can i compare only last 7 numbers in my query
Upvotes: 0
Views: 990
Reputation: 40218
You can use this code:
String numberToCheck;
if (numberToCheck.endsWith(number)) {
//do smth
}
This should do the job.
Upvotes: 0