Java Code Examples for android.telephony.PhoneNumberUtils#compare()
The following examples show how to use
android.telephony.PhoneNumberUtils#compare() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CallLogGroupBuilder.java From CSipSimple with GNU General Public License v3.0 | 5 votes |
private boolean equalNumbers(String number1, String number2) { // if (PhoneNumberUtils.isUriNumber(number1) || PhoneNumberUtils.isUriNumber(number2)) { // return compareSipAddresses(number1, number2); // } else { // Optim -- first try to compare very simply if(number1 != null && number2 != null && number1.equals(number2)) { return true; } return PhoneNumberUtils.compare(number1, number2); // } }
Example 2
Source File: Contact.java From DumbphoneAssistant with GNU General Public License v2.0 | 5 votes |
@Override public boolean equals(Object o) { if(!(o instanceof Contact)) { return false; } return PhoneNumberUtils.compare(number, ((Contact) o).number); }
Example 3
Source File: SmsConnSlot.java From Easer with GNU General Public License v3.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Telephony.Sms.Intents.SMS_RECEIVED_ACTION)) { try { Bundle bundle = intent.getExtras(); Object[] pdus = (Object[]) bundle.get("pdus"); SmsMessage[] msgs = new SmsMessage[pdus.length]; for (int i = 0; i < msgs.length; i++) { msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); String msg_from = msgs[i].getOriginatingAddress(); String msgBody = msgs[i].getMessageBody(); if (!Utils.isBlank(smsInnerData.sender)) { if (!PhoneNumberUtils.compare(context, msg_from, smsInnerData.sender)) { continue; } } if (!Utils.isBlank(smsInnerData.content)) { if (!msgBody.contains(smsInnerData.content)) { continue; } } Bundle dynamics = new Bundle(); dynamics.putString(SmsEventData.SenderDynamics.id, msg_from); dynamics.putString(SmsEventData.ContentDynamics.id, msgBody); changeSatisfiedState(true, dynamics); return; } changeSatisfiedState(false); } catch (Exception e) { Logger.d("Exception caught",e.getMessage()); } } }
Example 4
Source File: ControlModuleUserData.java From SimpleSmsRemote with MIT License | 5 votes |
public boolean isPhoneGranted(String phone) { for (String grantedPhone : grantedPhones) { if (PhoneNumberUtils.compare(phone, grantedPhone)) return true; } return false; }
Example 5
Source File: Contact.java From experimental-fall-detector-android-app with MIT License | 4 votes |
public static boolean check(Context context, String contact) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); String expected = preferences.getString(context.getString(R.string.contact), ""); return (PhoneNumberUtils.compare(contact, expected)); }
Example 6
Source File: TelephonyUtil.java From Silence with GNU General Public License v3.0 | 4 votes |
public static boolean isMyPhoneNumber(final Context context, String number){ return number != null && PhoneNumberUtils.compare(context, getPhoneNumber(context), number); }
Example 7
Source File: CancelAccountDeletionActivity.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
@Override public void onNextPressed() { if (getParentActivity() == null || nextPressed) { return; } TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE); boolean simcardAvailable = tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE; boolean allowCall = true; if (Build.VERSION.SDK_INT >= 23 && simcardAvailable) { //allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED; /*if (checkPermissions) { permissionsItems.clear(); if (!allowCall) { permissionsItems.add(Manifest.permission.READ_PHONE_STATE); } if (!permissionsItems.isEmpty()) { SharedPreferences preferences = MessagesController.getGlobalMainSettings(); if (preferences.getBoolean("firstlogin", true) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.READ_PHONE_STATE)) { preferences.edit().putBoolean("firstlogin", false).commit(); AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); builder.setMessage(LocaleController.getString("AllowReadCall", R.string.AllowReadCall)); permissionsDialog = showDialog(builder.create()); } else { getParentActivity().requestPermissions(permissionsItems.toArray(new String[permissionsItems.size()]), 6); } return; } }*/ } final TLRPC.TL_account_sendConfirmPhoneCode req = new TLRPC.TL_account_sendConfirmPhoneCode(); req.hash = hash; req.settings = new TLRPC.TL_codeSettings(); req.settings.allow_flashcall = false;//simcardAvailable && allowCall; req.settings.allow_app_hash = ApplicationLoader.hasPlayServices; SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); if (req.settings.allow_app_hash) { preferences.edit().putString("sms_hash", BuildVars.SMS_HASH).commit(); } else { preferences.edit().remove("sms_hash").commit(); } if (req.settings.allow_flashcall) { try { @SuppressLint("HardwareIds") String number = tm.getLine1Number(); if (!TextUtils.isEmpty(number)) { req.settings.current_number = PhoneNumberUtils.compare(phone, number); if (!req.settings.current_number) { req.settings.allow_flashcall = false; } } else { req.settings.current_number = false; } } catch (Exception e) { req.settings.allow_flashcall = false; FileLog.e(e); } } final Bundle params = new Bundle(); params.putString("phone", phone); nextPressed = true; ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { nextPressed = false; if (error == null) { fillNextCodeParams(params, (TLRPC.TL_auth_sentCode) response); } else { errorDialog = AlertsCreator.processError(currentAccount, error, CancelAccountDeletionActivity.this, req); } }), ConnectionsManager.RequestFlagFailOnServerErrors); }
Example 8
Source File: CancelAccountDeletionActivity.java From Telegram with GNU General Public License v2.0 | 4 votes |
@Override public void onNextPressed() { if (getParentActivity() == null || nextPressed) { return; } TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE); boolean simcardAvailable = tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE; boolean allowCall = true; if (Build.VERSION.SDK_INT >= 23 && simcardAvailable) { //allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED; /*if (checkPermissions) { permissionsItems.clear(); if (!allowCall) { permissionsItems.add(Manifest.permission.READ_PHONE_STATE); } if (!permissionsItems.isEmpty()) { SharedPreferences preferences = MessagesController.getGlobalMainSettings(); if (preferences.getBoolean("firstlogin", true) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.READ_PHONE_STATE)) { preferences.edit().putBoolean("firstlogin", false).commit(); AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); builder.setMessage(LocaleController.getString("AllowReadCall", R.string.AllowReadCall)); permissionsDialog = showDialog(builder.create()); } else { getParentActivity().requestPermissions(permissionsItems.toArray(new String[permissionsItems.size()]), 6); } return; } }*/ } final TLRPC.TL_account_sendConfirmPhoneCode req = new TLRPC.TL_account_sendConfirmPhoneCode(); req.hash = hash; req.settings = new TLRPC.TL_codeSettings(); req.settings.allow_flashcall = false;//simcardAvailable && allowCall; req.settings.allow_app_hash = ApplicationLoader.hasPlayServices; SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); if (req.settings.allow_app_hash) { preferences.edit().putString("sms_hash", BuildVars.SMS_HASH).commit(); } else { preferences.edit().remove("sms_hash").commit(); } if (req.settings.allow_flashcall) { try { @SuppressLint("HardwareIds") String number = tm.getLine1Number(); if (!TextUtils.isEmpty(number)) { req.settings.current_number = PhoneNumberUtils.compare(phone, number); if (!req.settings.current_number) { req.settings.allow_flashcall = false; } } else { req.settings.current_number = false; } } catch (Exception e) { req.settings.allow_flashcall = false; FileLog.e(e); } } final Bundle params = new Bundle(); params.putString("phone", phone); nextPressed = true; ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { nextPressed = false; if (error == null) { fillNextCodeParams(params, (TLRPC.TL_auth_sentCode) response); } else { errorDialog = AlertsCreator.processError(currentAccount, error, CancelAccountDeletionActivity.this, req); } }), ConnectionsManager.RequestFlagFailOnServerErrors); }
Example 9
Source File: RuleMatcher.java From callmeter with GNU General Public License v3.0 | 4 votes |
/** * Match a given log. * * @param log {@link Cursor} representing log * @return true if log matches */ boolean match(final Cursor log) { String number = log.getString(DataProvider.Logs.INDEX_REMOTE); if (number == null) { return false; } if (number.length() == 0) { return false; } Log.d(TAG, "NumbersGroup.match(", number, ")"); if (number.length() > 1) { if (stripLeadingZeros) { number = number.replaceFirst("^00*", ""); } if (intPrefix.length() > 1) { number = national2international(intPrefix, zeroPrefix, number); } } final int l = numbers.size(); for (int i = 0; i < l; i++) { String n = numbers.get(i); if (n == null) { Log.w(TAG, "numbers[", i, "] = null"); return false; } int nl = n.length(); if (nl <= 1) { Log.w(TAG, "#numbers[", i, "] = ", nl); return false; } if (n.startsWith("%")) { if (n.endsWith("%")) { if (nl == 2) { Log.w(TAG, "numbers[", i, "] = ", n); return false; } if (number.contains(n.substring(1, nl - 1))) { Log.d(TAG, "match: ", n); return true; } } else { if (number.endsWith(n.substring(1))) { Log.d(TAG, "match: ", n); return true; } } } else if (n.endsWith("%")) { if (number.startsWith(n.substring(0, nl - 1))) { Log.d(TAG, "match: ", n); return true; } } else if (PhoneNumberUtils.compare(number, n)) { Log.d(TAG, "match: ", n); return true; } Log.v(TAG, "no match: ", n); } return false; }