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


Java Phonenumber类代码示例

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


Phonenumber类属于com.google.i18n.phonenumbers包,在下文中一共展示了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;
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:25,代码来源:ShortCodeUtil.java

示例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);
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:24,代码来源:RegistrationActivity.java

示例3: generateConfigurationForEveryRhy

import com.google.i18n.phonenumbers.Phonenumber; //导入依赖的package包/类
@Transactional(readOnly = true, propagation = Propagation.MANDATORY, noRollbackFor = RuntimeException.class)
public List<SrvaCallRingConfiguration> generateConfigurationForEveryRhy() {
    final List<Organisation> rhyList = organisationRepository.findByOrganisationType(
            EnumSet.of(OrganisationType.RHY));

    final Map<Long, Set<Occupation>> allSrvaOccupations =
            occupationRepository.findActiveByOccupationTypeGroupByOrganisationId(OccupationType.SRVA_YHTEYSHENKILO);

    final Map<Long, Set<Occupation>> allContactPersons =
            occupationRepository.findActiveByOccupationTypeGroupByOrganisationId(OccupationType.TOIMINNANOHJAAJA);

    return rhyList.stream().map(rhy -> {
        final Set<Occupation> srva = allSrvaOccupations.getOrDefault(rhy.getId(), Collections.emptySet());
        final Set<Occupation> contactPersons = allContactPersons.getOrDefault(rhy.getId(), Collections.emptySet());

        final List<Phonenumber.PhoneNumber> phoneNumberList = getCallRingPhoneNumbers(srva);
        final List<String> notificationEmailList = getNotificationEmailList(rhy, contactPersons);

        // Repeat all phone numbers twice as fallback
        final List<Phonenumber.PhoneNumber> repeatedPhoneNumberList = F.concat(phoneNumberList, phoneNumberList);

        return new SrvaCallRingConfiguration(rhy.getOfficialCode(), repeatedPhoneNumberList, notificationEmailList);

    }).collect(toList());
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:26,代码来源:SrvaCallRingConfigurationService.java

示例4: 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;
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:21,代码来源:LabyrinttiSMSGatewayProvider.java

示例5: getNormalizedAddress

import com.google.i18n.phonenumbers.Phonenumber; //导入依赖的package包/类
/**
 * Formats address to normal form like +[country][prefix][localnumber]
 * @param address
 * @return
 */
private static String getNormalizedAddress(String address) {
    String number=stripAddress(address);
    try {
        //parse number using current locale rules
        Phonenumber.PhoneNumber phonenumber=phoneNumberUtil.parseAndKeepRawInput(number, Locale.getDefault().getCountry());
        //Phonenumber.PhoneNumber phonenumber = phoneNumberUtil.parse(number, Locale.getDefault().getCountry());
        //format to international form
        //phoneNumberUtil
        number=phoneNumberUtil.format(phonenumber, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL);
        //stripe any formatting symbols
        return stripAddress(number);
    }
    catch(Exception ex) {
        //in case of fail use default formatting rules
        number=PhoneNumberUtils.formatNumber(number);
        //stripe any formatting symbols
        return stripAddress(number);
    }
}
 
开发者ID:ivanovpv,项目名称:darksms,代码行数:25,代码来源:PhoneNumber.java

示例6: 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;
    }
}
 
开发者ID:ivanovpv,项目名称:darksms,代码行数:21,代码来源:PhoneNumber.java

示例7: 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;
}
 
开发者ID:nvanwyen,项目名称:libphonenumber-oracle,代码行数:17,代码来源:PhoneNumberImpl.java

示例8: 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;
}
 
开发者ID:nvanwyen,项目名称:libphonenumber-oracle,代码行数:17,代码来源:PhoneNumberImpl.java

示例9: 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;
}
 
开发者ID:nvanwyen,项目名称:libphonenumber-oracle,代码行数:17,代码来源:PhoneNumberImpl.java

示例10: 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;
}
 
开发者ID:nvanwyen,项目名称:libphonenumber-oracle,代码行数:17,代码来源:PhoneNumberImpl.java

示例11: 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;
}
 
开发者ID:nvanwyen,项目名称:libphonenumber-oracle,代码行数:17,代码来源:PhoneNumberImpl.java

示例12: 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;
}
 
开发者ID:nvanwyen,项目名称:libphonenumber-oracle,代码行数:17,代码来源:PhoneNumberImpl.java

示例13: 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;
}
 
开发者ID:nvanwyen,项目名称:libphonenumber-oracle,代码行数:17,代码来源:PhoneNumberImpl.java

示例14: isValidMobileNumber

import com.google.i18n.phonenumbers.Phonenumber; //导入依赖的package包/类
public Boolean isValidMobileNumber(String mobileNumber, String countryISO) {
    Boolean isValidNumber = false;

    try {
        Phonenumber.PhoneNumber mNumber = phoneNumberUtil.parse(mobileNumber, countryISO);
        if ("MX".equalsIgnoreCase(countryISO)) { // Temporary hardcode for mexico due to libphonenumber issue
        	isValidNumber = phoneNumberUtil.isValidNumber(mNumber);
        } else {
        	isValidNumber = phoneNumberUtil.isValidNumber(mNumber) &&
                    ( PhoneNumberUtil.PhoneNumberType.MOBILE.equals(phoneNumberUtil.getNumberType(mNumber)) ||
                      PhoneNumberUtil.PhoneNumberType.FIXED_LINE_OR_MOBILE.equals(phoneNumberUtil.getNumberType(mNumber))
                    );
        }
        
    } catch (NumberParseException ex) {
        myLog.debug(ex.getMessage(), ex);
    }

    return isValidNumber;
}
 
开发者ID:SECQME,项目名称:watchoverme-server,代码行数:21,代码来源:DefaultMobileNumberUtil.java

示例15: 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));
}
 
开发者ID:Aptoide,项目名称:aptoide-client-v8,代码行数:18,代码来源:ContactUtils.java


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