Example usage for android.telephony PhoneNumberUtils compare

List of usage examples for android.telephony PhoneNumberUtils compare

Introduction

In this page you can find the example usage for android.telephony PhoneNumberUtils compare.

Prototype

public static boolean compare(String a, String b) 

Source Link

Document

Compare phone numbers a and b, return true if they're identical enough for caller ID purposes.

Usage

From source file:Main.java

public static boolean comparePhones(String phone1, String phone2) {
    return PhoneNumberUtils.compare(phone1.trim(), phone2.trim());
}

From source file:com.callrecorder.android.FileHelper.java

private static String getContactName(String phoneNum, Context context) {
    @SuppressWarnings("deprecation")
    String res = PhoneNumberUtils.formatNumber(phoneNum);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context
            .checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
        return res;
    }/*from w w  w  .j a  v a2s .c om*/
    Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
    String[] projection = new String[] { ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
            ContactsContract.CommonDataKinds.Phone.NUMBER };
    Cursor names = context.getContentResolver().query(uri, projection, null, null, null);
    if (names == null)
        return res;

    int indexName = names.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
    int indexNumber = names.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);

    if (names.getCount() > 0) {
        names.moveToFirst();
        do {
            String name = names.getString(indexName);
            String number = cleanNumber(names.getString(indexNumber));

            if (PhoneNumberUtils.compare(number, phoneNum)) {
                res = name;
                break;
            }
        } while (names.moveToNext());
    }
    names.close();

    return res;
}

From source file:com.moez.QKSMS.mmssms.Transaction.java

private String fetchRnrSe(String authToken, Context context) throws ExecutionException, InterruptedException {
    JsonObject userInfo = Ion.with(context).load("https://www.google.com/voice/request/user")
            .setHeader("Authorization", "GoogleLogin auth=" + authToken).asJsonObject().get();

    String rnrse = userInfo.get("r").getAsString();

    try {/* w ww.  j  a  v a 2  s  . c  om*/
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
        String number = tm.getLine1Number();
        if (number != null) {
            JsonObject phones = userInfo.getAsJsonObject("phones");
            for (Map.Entry<String, JsonElement> entry : phones.entrySet()) {
                JsonObject phone = entry.getValue().getAsJsonObject();
                if (!PhoneNumberUtils.compare(number, phone.get("phoneNumber").getAsString()))
                    continue;
                if (!phone.get("smsEnabled").getAsBoolean())
                    break;

                Ion.with(context).load("https://www.google.com/voice/settings/editForwardingSms/")
                        .setHeader("Authorization", "GoogleLogin auth=" + authToken)
                        .setBodyParameter("phoneId", entry.getKey()).setBodyParameter("enabled", "0")
                        .setBodyParameter("_rnr_se", rnrse).asJsonObject();
                break;
            }
        }
    } catch (Exception e) {

    }

    // broadcast so you can save it to your shared prefs or something so that it doesn't need to be retrieved every time
    Intent intent = new Intent(VOICE_TOKEN);
    intent.putExtra("_rnr_se", rnrse);
    context.sendBroadcast(intent);

    return rnrse;
}

From source file:com.android.mms.ui.MessageUtils.java

public static boolean isLocalNumber(String number) {
    if (number == null) {
        return false;
    }//from ww w.  j ava 2 s  .c  om

    // we don't use Mms.isEmailAddress() because it is too strict for comparing addresses like
    // "foo+caf_=6505551212=tmomail.net@gmail.com",
    // which is the 'from' address from a forwarded email
    // message from Gmail. We don't want to treat "foo+caf
    // =6505551212=tmomail.net@gmail.com" and
    // "6505551212" to be the same.
    if (number.indexOf('@') >= 0) {
        return false;
    }

    List<SubscriptionInfo> subInfoList;
    subInfoList = SubscriptionManager.from(MmsApp.getApplication()).getActiveSubscriptionInfoList();
    if (subInfoList == null || subInfoList.size() == 0) {
        MmsLog.d(TAG, "isLocalNumber SIM not insert");
        return false;
    }
    for (SubscriptionInfo subInfoRecord : subInfoList) {
        // modify BUG_ID:JWYYL-16 chenweihua 20141216 (start)
        /*
        if (PhoneNumberUtils.compare(number, getLocalNumber(subInfoRecord.getSubscriptionId()))) {
           return true;
        }
        */
        if (android.os.SystemProperties.getInt("ro.rgk_brazil_number_match", 0) == 1) {
            if (PhoneNumberUtils.compareWithAreaCode(number,
                    getLocalNumber(subInfoRecord.getSubscriptionId()))) {
                return true;
            }
        } else {
            if (PhoneNumberUtils.compare(number, getLocalNumber(subInfoRecord.getSubscriptionId()))) {
                return true;
            }
        }
        // modify BUG_ID:JWYYL-16 chenweihua 20141216 (end)
    }
    return false;
}

From source file:com.android.messaging.mmslib.pdu.PduPersister.java

/**
 * For a given address type, extract the recipients from the headers.
 *
 * @param recipients      a HashSet that is loaded with the recipients from the FROM or TO
 *                        headers//from  w  w w. jav a2  s.c  om
 * @param addressMap      a HashMap of the addresses from the ADDRESS_FIELDS header
 * @param selfNumber      self phone number
 */
private void checkAndLoadToCcRecipients(final HashSet<String> recipients,
        final SparseArray<EncodedStringValue[]> addressMap, final String selfNumber) {
    final EncodedStringValue[] arrayTo = addressMap.get(PduHeaders.TO);
    final EncodedStringValue[] arrayCc = addressMap.get(PduHeaders.CC);
    final ArrayList<String> numbers = new ArrayList<String>();
    if (arrayTo != null) {
        for (final EncodedStringValue v : arrayTo) {
            if (v != null) {
                numbers.add(v.getString());
            }
        }
    }
    if (arrayCc != null) {
        for (final EncodedStringValue v : arrayCc) {
            if (v != null) {
                numbers.add(v.getString());
            }
        }
    }
    for (final String number : numbers) {
        // Only add numbers which aren't my own number.
        if (TextUtils.isEmpty(selfNumber) || !PhoneNumberUtils.compare(number, selfNumber)) {
            if (!recipients.contains(number)) {
                // Only add numbers which aren't already included.
                recipients.add(number);
            }
        }
    }
}