当前位置: 首页>>代码示例>>Java>>正文


Java PhoneNumberUtil.parse方法代码示例

本文整理汇总了Java中com.google.i18n.phonenumbers.PhoneNumberUtil.parse方法的典型用法代码示例。如果您正苦于以下问题:Java PhoneNumberUtil.parse方法的具体用法?Java PhoneNumberUtil.parse怎么用?Java PhoneNumberUtil.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.i18n.phonenumbers.PhoneNumberUtil的用法示例。


在下文中一共展示了PhoneNumberUtil.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendOTPNumber

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的package包/类
private void sendOTPNumber(){
	if(checkNull()){
		PhoneNumberUtil util = PhoneNumberUtil.getInstance();
		// assuming you only a button in your layout...
		boolean isAuthentic = false;
		try {
			PhoneNumber number = util.parse(countryPrefix + edtMobile.getText().toString().trim(), countryIso);
			isAuthentic = true;
		} catch (NumberParseException e) {
			e.printStackTrace();
		}
		if (isAuthentic) {
			comman.hideSoftKeyBoard(context, edtMobile);
			createJson(edtMobile.getText().toString().trim(), countryPrefix, countryName);
		}
	}
}
 
开发者ID:mityung,项目名称:XERUNG,代码行数:18,代码来源:SignIn.java

示例2: isShortCode

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的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;
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:25,代码来源:ShortCodeUtil.java

示例3: initializeNumber

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的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);
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:24,代码来源:RegistrationActivity.java

示例4: formatE164

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的package包/类
public static String formatE164(String countryCode, String number) {
  try {
    PhoneNumberUtil util     = PhoneNumberUtil.getInstance();
    int parsedCountryCode    = Integer.parseInt(countryCode);
    PhoneNumber parsedNumber = util.parse(number,
                                          util.getRegionCodeForCountryCode(parsedCountryCode));

    return util.format(parsedNumber, PhoneNumberUtil.PhoneNumberFormat.E164);
  } catch (NumberParseException | NumberFormatException npe) {
    Log.w(TAG, npe);
  }

  return "+"                                                     +
      countryCode.replaceAll("[^0-9]", "").replaceAll("^0*", "") +
      number.replaceAll("[^0-9]", "");
}
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:17,代码来源:PhoneNumberFormatter.java

示例5: updateContactName

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的package包/类
private void updateContactName(String phone) {
    mPhoneContactNumber = phone;
    mPhoneContactName = phone;

    try {
        // phone must begin with '+'
        PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
        PhoneNumber numberProto = phoneUtil.parse(phone, "");
        String countryCode = "+" + String.valueOf(numberProto.getCountryCode());
        String formatedPhoneNumber = phoneUtil.format(numberProto, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL);
        Contact contact = AppManager.getInstance().getPhoneContactFromContacts(phoneContacts, phone, countryCode);
        if (contact == null) {
            mPhoneContactName = formatedPhoneNumber;
        } else {
            mPhoneContactName = contact.getName();
        }
    } catch (NumberParseException e) {
        System.err.println("NumberParseException was thrown: " + e.toString());
    }

    tvUsername.setText(mPhoneContactName);
}
 
开发者ID:AppHero2,项目名称:Raffler-Android,代码行数:23,代码来源:ChatListRecyclerViewAdapter.java

示例6: validatePhone

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的package包/类
public static boolean validatePhone(String phone, String countryCode) {
  PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
  if (!ProjectUtil.isStringNullOREmpty(countryCode) && (countryCode.charAt(0) != '+')) {
    countryCode = "+" + countryCode;
  }
  try {
    if (isStringNullOREmpty(countryCode)) {
      countryCode = PropertiesCache.getInstance().getProperty("sunbird_default_country_code");
    }
    phone = countryCode + "-" + phone;
    PhoneNumber numberProto = phoneUtil.parse(phone, "");
    // phoneUtil.isValidNumber(number)
    ProjectLogger.log("Number is of region - " + numberProto.getCountryCode() + " "
        + phoneUtil.getRegionCodeForNumber(numberProto));
    ProjectLogger.log("Is the input number valid - "
        + (phoneUtil.isValidNumber(numberProto) == true ? "Yes" : "No"));
    return phoneUtil.isValidNumber(numberProto);
  } catch (NumberParseException e) {
    ProjectLogger.log("Exception occurred while validating phone number : ", e);
    ProjectLogger.log(phone + "this phone no. is not a valid one.");
  }
  return false;
}
 
开发者ID:project-sunbird,项目名称:sunbird-utils,代码行数:24,代码来源:ProjectUtil.java

示例7: convertPhoneNumberToE164

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的package包/类
public static String convertPhoneNumberToE164(Context context, String ph_no) {
	PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
	PhoneNumber pn = null;
	String temp_ph_no = null;
	try {
		pn = phoneNumberUtil.parse(ph_no, "");
		temp_ph_no = phoneNumberUtil.format(pn, PhoneNumberFormat.E164);
	} catch (Exception e) {
		try {
			pn = phoneNumberUtil.parse(ph_no,
					((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE))
							.getSimCountryIso().toUpperCase());
			temp_ph_no = phoneNumberUtil.format(pn, PhoneNumberFormat.E164);
		} catch (Exception ee) {
			FirebaseCrash.log(ee.getStackTrace().toString());
		}
	}
	return temp_ph_no;
}
 
开发者ID:arunrajora,项目名称:Chit-Chat,代码行数:20,代码来源:Utils.java

示例8: isValidNumberInE164Format

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的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));
}
 
开发者ID:Aptoide,项目名称:aptoide-client-v8,代码行数:18,代码来源:ContactUtils.java

示例9: initializeNumber

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的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);
  }
}
 
开发者ID:redcracker,项目名称:TextSecure,代码行数:24,代码来源:RegistrationActivity.java

示例10: convertToE164

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的package包/类
/**
 * Helper method to convert a phone number to E164 format as expected by the server
 * (+1XXXXXXXXXX)
 *
 * @param raw_phone_number The unformatted phone number as stored by the system contacts
 *                         application
 * @return String storing the E164-formatted phone number
 */
public static String convertToE164(String raw_phone_number) {
    PhoneNumberUtil phone_util = PhoneNumberUtil.getInstance();
    try {
        Phonenumber.PhoneNumber phone_proto = phone_util.parse(raw_phone_number,
                Constants.DEFAULT_PHONE_REGION);
        if (phone_util.isValidNumber(phone_proto)) {
            return phone_util.format(phone_proto, PhoneNumberUtil.PhoneNumberFormat.E164);
        } else {
            Log.d(TAG, "Invalid number");
            return null;
        }
    } catch (NumberParseException e) {
        Log.d(TAG, "Error parsing phone number");
        return null;
    }
}
 
开发者ID:whereuat,项目名称:whereuat-android,代码行数:25,代码来源:PhonebookUtils.java

示例11: checkPhoneNumber

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的package包/类
static void checkPhoneNumber(String phoneNumberStr)
        throws NumberParseException, IllegalArgumentException {

    if (phoneNumberStr == null || phoneNumberStr.length() == 0) {
        throw new IllegalArgumentException("Phone number is empty");
    } else if (phoneNumberStr.charAt(0) != '+') {
        throw new IllegalArgumentException("Phone number should start with '+'");
    }

    PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
    Phonenumber.PhoneNumber phoneNumber = phoneUtil.parse(phoneNumberStr, null);
    // throws NumberParseException

    if (!phoneUtil.isValidNumber(phoneNumber)) {
        throw new IllegalArgumentException(phoneNumberStr + " is not valid phone number");
    }
}
 
开发者ID:Cryptonomica,项目名称:cryptonomica,代码行数:18,代码来源:TwilioUtils.java

示例12: validateThenFormatMobileNumber

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的package包/类
private String validateThenFormatMobileNumber(String phone) {
    try {
        PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
        Phonenumber.PhoneNumber phoneNumber = phoneNumberUtil.parse(phone, "+86");
        if (phoneNumberUtil.isValidNumber(phoneNumber) && (
                phoneNumberUtil.getNumberType(phoneNumber)
                == PhoneNumberUtil.PhoneNumberType.MOBILE
                || phoneNumberUtil.getNumberType(phoneNumber)
                   == PhoneNumberUtil.PhoneNumberType.FIXED_LINE_OR_MOBILE)) {
            return phoneNumberUtil.format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.E164);
        } else {
            return "";
        }
    } catch (NumberParseException e) {
        return "";
    }
}
 
开发者ID:Piasy,项目名称:YaMvp,代码行数:18,代码来源:MainPresenter.java

示例13: testPhoneNumberParse3

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的package包/类
@Test
public void testPhoneNumberParse3() throws Exception {

    String phoneNumberString = "072 916 6903";
    PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();

    try {

        Phonenumber.PhoneNumber phoneNumber = phoneNumberUtil.parse(phoneNumberString,"ZA");
        log.info("{}", phoneNumberUtil.format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.E164));
        log.info("Country Code: {}", phoneNumber.getCountryCode()) ;
        log.info("Country Source: {}", phoneNumber.getCountryCodeSource()) ;
        log.info("National Number: {}", phoneNumber.getNationalNumber()) ;
        log.info("National Number: {}", phoneNumber.getNationalNumber()) ;
        assertTrue(  phoneNumberUtil.isValidNumber(phoneNumber));


    }catch (Exception e)
    {
        log.error(e.getMessage());
    }

}
 
开发者ID:grassrootza,项目名称:grassroot-platform,代码行数:24,代码来源:PhoneNumberParsingTest.java

示例14: isValid

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的package包/类
public static boolean isValid(Context context, String aNumber) {
    if (aNumber == null) { return false; }

    PhoneNumberUtil pnu = PhoneNumberUtil.getInstance();
    Locale locale = context.getResources().getConfiguration().locale;
    String countryIso = getCurrentCountryIso(context, locale);
    Phonenumber.PhoneNumber swissNumberProto;
    try {
        swissNumberProto = pnu.parse(aNumber, countryIso);
        return pnu.isValidNumber(swissNumberProto)
                // ignore ivory coast numbers (libphonenumber does not recognize those properly)
                || swissNumberProto.getCountryCode() == 225 ;
    } catch (NumberParseException e) {
        Log.w(LOGTAG, "isValid caught NumberParseException: number=" + aNumber);
        return false;
    }
}
 
开发者ID:doerfli,项目名称:leavemealone,代码行数:18,代码来源:PhoneNumberHelper.java

示例15: isTaggableDestination

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的package包/类
public static boolean isTaggableDestination(Recipients recipients){
  // Be safe - err on the side of not tagging

  if (recipients.isGroupRecipient())
    return false;

  PhoneNumberUtil util = PhoneNumberUtil.getInstance();
  try {
    PhoneNumber num = util.parse(recipients.getPrimaryRecipient().getNumber(),
                                 Locale.getDefault().getCountry());
    PhoneNumberType type = util.getNumberType(num);

    Log.d(TAG, "Number type: " + type.toString());

    return type == PhoneNumberType.FIXED_LINE ||
           type == PhoneNumberType.MOBILE     ||
           type == PhoneNumberType.FIXED_LINE_OR_MOBILE;
  }
  catch (NumberParseException e){
    Log.w(TAG, "Couldn't get number type (country: " + Locale.getDefault().getCountry() + ")");
    return false;
  }
}
 
开发者ID:SilenceIM,项目名称:Silence,代码行数:24,代码来源:AutoInitiate.java


注:本文中的com.google.i18n.phonenumbers.PhoneNumberUtil.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。