Hello everyone I am programming a call blocker app. My problem is that I can not compare the incoming phone number to the contact list because the phone numbers in the contact list come in a bad format.
For example:
- Incoming call format yyyxxxxxxxx (local area code)+(phone number) example: 261xxxxxxx
- Contacts list format xxxxxxxx (phone number)
This is how i access contact list:
return new CursorLoader(
getActivity(), // Parent activity context
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, // Table to query
new String[]{
ContactsContract.CommonDataKinds.Phone.NUMBER,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID,
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
}, // Projection to return
null,
null, // No selection arguments
null // Default sort order
...
String phoneNumber = data.getString(data.getColumnIndex(loader.getId() == LOAD_CONTACTS_CURSOR ? ContactsContract.CommonDataKinds.Phone.NUMBER : CallLog.Calls.NUMBER));
);
This is how i access incoming call:
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_RINGING)) {
final Strng incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER));
}
}
How can I get the local area code not country code. so I can compare the incoming numbers with those in the contact list?
Best regards.