use of com.android.i18n.phonenumbers.PhoneNumberUtil in project platform_frameworks_base by android.
the class LinkSpec method gatherTelLinks.
private static final void gatherTelLinks(ArrayList<LinkSpec> links, Spannable s) {
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
Iterable<PhoneNumberMatch> matches = phoneUtil.findNumbers(s.toString(), Locale.getDefault().getCountry(), Leniency.POSSIBLE, Long.MAX_VALUE);
for (PhoneNumberMatch match : matches) {
LinkSpec spec = new LinkSpec();
spec.url = "tel:" + PhoneNumberUtils.normalizeNumber(match.rawString());
spec.start = match.start();
spec.end = match.end();
links.add(spec);
}
}
use of com.android.i18n.phonenumbers.PhoneNumberUtil in project platform_frameworks_base by android.
the class CallerInfo method getGeoDescription.
/**
* @return a geographical description string for the specified number.
* @see com.android.i18n.phonenumbers.PhoneNumberOfflineGeocoder
*/
private static String getGeoDescription(Context context, String number) {
if (VDBG)
Rlog.v(TAG, "getGeoDescription('" + number + "')...");
if (TextUtils.isEmpty(number)) {
return null;
}
PhoneNumberUtil util = PhoneNumberUtil.getInstance();
PhoneNumberOfflineGeocoder geocoder = PhoneNumberOfflineGeocoder.getInstance();
Locale locale = context.getResources().getConfiguration().locale;
String countryIso = getCurrentCountryIso(context, locale);
PhoneNumber pn = null;
try {
if (VDBG)
Rlog.v(TAG, "parsing '" + number + "' for countryIso '" + countryIso + "'...");
pn = util.parse(number, countryIso);
if (VDBG)
Rlog.v(TAG, "- parsed number: " + pn);
} catch (NumberParseException e) {
Rlog.w(TAG, "getGeoDescription: NumberParseException for incoming number '" + Rlog.pii(TAG, number) + "'");
}
if (pn != null) {
String description = geocoder.getDescriptionForNumber(pn, locale);
if (VDBG)
Rlog.v(TAG, "- got description: '" + description + "'");
return description;
} else {
return null;
}
}
use of com.android.i18n.phonenumbers.PhoneNumberUtil in project XobotOS by xamarin.
the class PhoneNumberUtils method formatNumberToE164.
/**
* Format the given phoneNumber to the E.164 representation.
* <p>
* The given phone number must have an area code and could have a country
* code.
* <p>
* The defaultCountryIso is used to validate the given number and generate
* the E.164 phone number if the given number doesn't have a country code.
*
* @param phoneNumber
* the phone number to format
* @param defaultCountryIso
* the ISO 3166-1 two letters country code
* @return the E.164 representation, or null if the given phone number is
* not valid.
*
* @hide
*/
public static String formatNumberToE164(String phoneNumber, String defaultCountryIso) {
PhoneNumberUtil util = PhoneNumberUtil.getInstance();
String result = null;
try {
PhoneNumber pn = util.parse(phoneNumber, defaultCountryIso);
if (util.isValidNumber(pn)) {
result = util.format(pn, PhoneNumberFormat.E164);
}
} catch (NumberParseException e) {
}
return result;
}
use of com.android.i18n.phonenumbers.PhoneNumberUtil in project android_frameworks_base by ParanoidAndroid.
the class PhoneNumberUtils method formatNumberToE164.
/**
* Format the given phoneNumber to the E.164 representation.
* <p>
* The given phone number must have an area code and could have a country
* code.
* <p>
* The defaultCountryIso is used to validate the given number and generate
* the E.164 phone number if the given number doesn't have a country code.
*
* @param phoneNumber
* the phone number to format
* @param defaultCountryIso
* the ISO 3166-1 two letters country code
* @return the E.164 representation, or null if the given phone number is
* not valid.
*
* @hide
*/
public static String formatNumberToE164(String phoneNumber, String defaultCountryIso) {
PhoneNumberUtil util = PhoneNumberUtil.getInstance();
String result = null;
try {
PhoneNumber pn = util.parse(phoneNumber, defaultCountryIso);
if (util.isValidNumber(pn)) {
result = util.format(pn, PhoneNumberFormat.E164);
}
} catch (NumberParseException e) {
}
return result;
}
use of com.android.i18n.phonenumbers.PhoneNumberUtil in project XobotOS by xamarin.
the class CallerInfo method getGeoDescription.
/**
* @return a geographical description string for the specified number.
* @see com.android.i18n.phonenumbers.PhoneNumberOfflineGeocoder
*/
private static String getGeoDescription(Context context, String number) {
if (VDBG)
Log.v(TAG, "getGeoDescription('" + number + "')...");
if (TextUtils.isEmpty(number)) {
return null;
}
PhoneNumberUtil util = PhoneNumberUtil.getInstance();
PhoneNumberOfflineGeocoder geocoder = PhoneNumberOfflineGeocoder.getInstance();
Locale locale = context.getResources().getConfiguration().locale;
String countryIso = getCurrentCountryIso(context, locale);
PhoneNumber pn = null;
try {
if (VDBG)
Log.v(TAG, "parsing '" + number + "' for countryIso '" + countryIso + "'...");
pn = util.parse(number, countryIso);
if (VDBG)
Log.v(TAG, "- parsed number: " + pn);
} catch (NumberParseException e) {
Log.w(TAG, "getGeoDescription: NumberParseException for incoming number '" + number + "'");
}
if (pn != null) {
String description = geocoder.getDescriptionForNumber(pn, locale);
if (VDBG)
Log.v(TAG, "- got description: '" + description + "'");
return description;
} else {
return null;
}
}
Aggregations