本文整理汇总了Java中com.google.i18n.phonenumbers.Phonenumber.PhoneNumber方法的典型用法代码示例。如果您正苦于以下问题:Java Phonenumber.PhoneNumber方法的具体用法?Java Phonenumber.PhoneNumber怎么用?Java Phonenumber.PhoneNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.i18n.phonenumbers.Phonenumber
的用法示例。
在下文中一共展示了Phonenumber.PhoneNumber方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isShortCode
import com.google.i18n.phonenumbers.Phonenumber; //导入方法依赖的package包/类
public static boolean isShortCode(@NonNull String localNumber, @NonNull String number) {
try {
PhoneNumberUtil util = PhoneNumberUtil.getInstance();
Phonenumber.PhoneNumber localNumberObject = util.parse(localNumber, null);
String localCountryCode = util.getRegionCodeForNumber(localNumberObject);
String bareNumber = number.replaceAll("[^0-9+]", "");
// libphonenumber doesn't seem to be correct for Germany and Finland
if (bareNumber.length() <= 6 && ("DE".equals(localCountryCode) || "FI".equals(localCountryCode) || "SK".equals(localCountryCode))) {
return true;
}
// libphonenumber seems incorrect for Russia and a few other countries with 4 digit short codes.
if (bareNumber.length() <= 4 && !SHORT_COUNTRIES.contains(localCountryCode)) {
return true;
}
Phonenumber.PhoneNumber shortCode = util.parse(number, localCountryCode);
return ShortNumberInfo.getInstance().isPossibleShortNumberForRegion(shortCode, localCountryCode);
} catch (NumberParseException e) {
Log.w(TAG, e);
return false;
}
}
示例2: initializeNumber
import com.google.i18n.phonenumbers.Phonenumber; //导入方法依赖的package包/类
private void initializeNumber() {
PhoneNumberUtil numberUtil = PhoneNumberUtil.getInstance();
String localNumber = Util.getDeviceE164Number(this);
try {
if (!TextUtils.isEmpty(localNumber)) {
Phonenumber.PhoneNumber localNumberObject = numberUtil.parse(localNumber, null);
if (localNumberObject != null) {
this.countryCode.setText(String.valueOf(localNumberObject.getCountryCode()));
this.number.setText(String.valueOf(localNumberObject.getNationalNumber()));
}
} else {
String simCountryIso = Util.getSimCountryIso(this);
if (!TextUtils.isEmpty(simCountryIso)) {
this.countryCode.setText(numberUtil.getCountryCodeForRegion(simCountryIso)+"");
}
}
} catch (NumberParseException npe) {
Log.w(TAG, npe);
}
}
示例3: truncate_number
import com.google.i18n.phonenumbers.Phonenumber; //导入方法依赖的package包/类
public static String truncate_number( String phone )
{
String val = "";
try
{
Phonenumber.PhoneNumber num = utl_.parse( phone, "" );
val = format( phone, "", FORMAT_INTERNATIONAL );
}
catch ( Exception e )
{
val = phone;
}
return val;
}
示例4: get_national
import com.google.i18n.phonenumbers.Phonenumber; //导入方法依赖的package包/类
public static long get_national( String phone, String region )
{
long val = 0;
try
{
Phonenumber.PhoneNumber num = utl_.parse( phone, region );
val = num.getNationalNumber();
}
catch ( Exception e )
{
val = 0;
}
return val;
}
示例5: isValidNumberInE164Format
import com.google.i18n.phonenumbers.Phonenumber; //导入方法依赖的package包/类
public boolean isValidNumberInE164Format(String number) {
final PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
Phonenumber.PhoneNumber phoneNumber = null;
int country;
try {
phoneNumber = phoneNumberUtil.parse(number, "");
country = phoneNumber.getCountryCode();
} catch (NumberParseException e) {
e.printStackTrace();
return false;
}
return phoneNumberUtil.isValidNumberForRegion(phoneNumber,
phoneNumberUtil.getRegionCodeForCountryCode(country));
}
示例6: initializeNumber
import com.google.i18n.phonenumbers.Phonenumber; //导入方法依赖的package包/类
private void initializeNumber() {
PhoneNumberUtil numberUtil = PhoneNumberUtil.getInstance();
String localNumber = Util.getDeviceE164Number(this);
try {
if (!TextUtils.isEmpty(localNumber)) {
Phonenumber.PhoneNumber localNumberObject = numberUtil.parse(localNumber, null);
if (localNumberObject != null) {
this.countryCode.setText(localNumberObject.getCountryCode()+"");
this.number.setText(localNumberObject.getNationalNumber()+"");
}
} else {
String simCountryIso = ((TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE)).getSimCountryIso();
if (!TextUtils.isEmpty(simCountryIso)) {
this.countryCode.setText(numberUtil.getCountryCodeForRegion(simCountryIso.toUpperCase())+"");
}
}
} catch (NumberParseException npe) {
Log.w("CreateAccountActivity", npe);
}
}
示例7: sendMessage
import com.google.i18n.phonenumbers.Phonenumber; //导入方法依赖的package包/类
@Override
public SMSPersistentMessage sendMessage(Phonenumber.PhoneNumber phoneNumber, String messageText) {
final SMSPersistentMessage message = new SMSPersistentMessage();
message.setStatus(SMSMessageStatus.PENDING, null);
message.setDirection(SMSPersistentMessage.Direction.OUT);
message.setNumberTo(PhoneNumberUtil.getInstance().format(
phoneNumber, PhoneNumberUtil.PhoneNumberFormat.E164));
message.setMessage(messageText);
try {
sendMessage(message);
} catch (Exception ex) {
LOG.error("SMS send to number " + message.getNumberTo() + " has failed", ex);
message.setErrorStatus(ex);
}
return message;
}
示例8: compareDefault
import com.google.i18n.phonenumbers.Phonenumber; //导入方法依赖的package包/类
public boolean compareDefault(String address) {
try {
Phonenumber.PhoneNumber phoneNumber=phoneNumberUtil.parse(address, Locale.getDefault().getCountry());
PhoneNumberUtil.MatchType matchType=phoneNumberUtil.isNumberMatch(phoneNumber, this.getRawAddress());
if(matchType == PhoneNumberUtil.MatchType.EXACT_MATCH ||
matchType== PhoneNumberUtil.MatchType.NSN_MATCH ||
matchType == PhoneNumberUtil.MatchType.SHORT_NSN_MATCH)
return true;
matchType=phoneNumberUtil.isNumberMatch(phoneNumber, this.getNormalAddress());
if(matchType == PhoneNumberUtil.MatchType.EXACT_MATCH ||
matchType== PhoneNumberUtil.MatchType.NSN_MATCH ||
matchType == PhoneNumberUtil.MatchType.SHORT_NSN_MATCH)
return true;
return false;
}
catch(Exception e) {
Log.w(TAG, "Error comparing addresses='"+this.rawAddress+"' and '"+address+"'", e);
return false;
}
}
示例9: format
import com.google.i18n.phonenumbers.Phonenumber; //导入方法依赖的package包/类
public static String format( String phone, String region, int style )
{
String val = "";
try
{
Phonenumber.PhoneNumber num = utl_.parse( phone, region );
val = utl_.format( num, format_to_enum( style ) );
}
catch ( Exception e )
{
val = phone;
}
return val;
}
示例10: get_region_code
import com.google.i18n.phonenumbers.Phonenumber; //导入方法依赖的package包/类
public static String get_region_code( String phone )
{
String val = "";
try
{
Phonenumber.PhoneNumber num = utl_.parse( phone, "" );
val = utl_.getRegionCodeForNumber( num );
}
catch ( Exception e )
{
val = "";
}
return val;
}
示例11: get_type
import com.google.i18n.phonenumbers.Phonenumber; //导入方法依赖的package包/类
public static int get_type( String phone, String region )
{
int val = TYPE_UNKNOWN;
try
{
Phonenumber.PhoneNumber num = utl_.parse( phone, region );
val = enum_to_type( utl_.getNumberType( num ) );
}
catch ( Exception e )
{
val = TYPE_UNKNOWN;
}
return val;
}
示例12: get_countrycode
import com.google.i18n.phonenumbers.Phonenumber; //导入方法依赖的package包/类
public static int get_countrycode( String phone, String region )
{
int val = 0;
try
{
Phonenumber.PhoneNumber num = utl_.parse( phone, region );
val = num.getCountryCode();
}
catch ( Exception e )
{
val = 0;
}
return val;
}
示例13: is_valid_for_region
import com.google.i18n.phonenumbers.Phonenumber; //导入方法依赖的package包/类
public static boolean is_valid_for_region( String phone, String region )
{
boolean ok = false;
try
{
Phonenumber.PhoneNumber num = utl_.parse( phone, region );
ok = utl_.isValidNumberForRegion( num, region );
}
catch ( Exception e )
{
ok = false;
}
return ok;
}
示例14: evaluate
import com.google.i18n.phonenumbers.Phonenumber; //导入方法依赖的package包/类
/**
* @see Test#evaluate(Runner, RunState, EvaluationContext, String)
*/
@Override
public Result evaluate(Runner runner, RunState run, EvaluationContext context, String text) {
String country = run.getOrg().getCountry();
PhoneNumberUtil numberUtil = PhoneNumberUtil.getInstance();
// try to find a phone number in the text we have been sent
Iterable<PhoneNumberMatch> matches = numberUtil.findNumbers(text, country);
// try it as an international number if we failed
if (!matches.iterator().hasNext()) {
matches = numberUtil.findNumbers("+" + text, country);
}
if (matches.iterator().hasNext()) {
Phonenumber.PhoneNumber number = matches.iterator().next().number();
return Result.match(numberUtil.format(number, PhoneNumberUtil.PhoneNumberFormat.E164));
} else {
return Result.NO_MATCH;
}
}
示例15: formatNumber
import com.google.i18n.phonenumbers.Phonenumber; //导入方法依赖的package包/类
/**
* Format a phone number.
* <p>
* If the given number doesn't have the country code, the phone will be
* formatted to the default country's convention.
*
* @param phoneNumber
* the number to be formatted.
* @param defaultCountryIso
* the ISO 3166-1 two letters country code whose convention will
* be used if the given number doesn't have the country code.
* @return the formatted number, or null if the given number is not valid.
*
*/
@SuppressLint("Override")
public static String formatNumber(String phoneNumber, String defaultCountryIso) {
// Do not attempt to format numbers that start with a hash or star symbol.
if (phoneNumber.startsWith("#") || phoneNumber.startsWith("*")) {
return phoneNumber;
}
PhoneNumberUtil util = PhoneNumberUtil.getInstance();
String result = null;
try {
Phonenumber.PhoneNumber pn = util.parseAndKeepRawInput(phoneNumber, defaultCountryIso);
result = util.formatInOriginalFormat(pn, defaultCountryIso);
} catch (NumberParseException e) {
}
return result;
}