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


Java PhoneNumberUtils.stripSeparators方法代码示例

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


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

示例1: getContactNameByPhoneNumber

import android.telephony.PhoneNumberUtils; //导入方法依赖的package包/类
/**
 *
 * @param context
 * @param sourcePhoneNumber //phone number as-is
 * @return null if not in contacts. array[0] - Display name, [1] - contactId
 */
private String[] getContactNameByPhoneNumber(Context context, String sourcePhoneNumber) {
    String phoneNumber = PhoneNumberUtils.stripSeparators(sourcePhoneNumber);
    String contactInfo[] = null;
    if(phoneNumber==null || phoneNumber.trim().length()==0) {
        return contactInfo;
    }
    Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
    String[] projection = new String[] {ContactsContract.PhoneLookup.DISPLAY_NAME,
            ContactsContract.PhoneLookup._ID,
            ContactsContract.PhoneLookup.LAST_TIME_CONTACTED};

    Cursor cursor = context.getContentResolver().query(uri, projection, null, null, ContactDAO.LAST_CONTACT_DATE_DESC);
    if(cursor.moveToFirst()) {
        contactInfo = new String[2];
        contactInfo[0] = cursor.getString(0);
        contactInfo[1] = cursor.getString(1);
    }
    cursor.close();
    return contactInfo;
}
 
开发者ID:ivanovpv,项目名称:darksms,代码行数:27,代码来源:MessageDAO.java

示例2: convertToString

import android.telephony.PhoneNumberUtils; //导入方法依赖的package包/类
@Override
 public final CharSequence convertToString(Cursor cursor) {
 	CharSequence number = ContactsWrapper.getInstance().transformToSipUri(mContext, cursor);
     boolean isExternalPhone = ContactsWrapper.getInstance().isExternalPhoneNumber(mContext, cursor);
 	if(!TextUtils.isEmpty(number) && isExternalPhone) {
 	    String stripNbr = PhoneNumberUtils.stripSeparators(number.toString());
return Filter.rewritePhoneNumber(mContext, currentAccId, stripNbr);
 	}
 	return number;
 }
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:11,代码来源:ContactsSearchAdapter.java

示例3: applyRewritingInfo

import android.telephony.PhoneNumberUtils; //导入方法依赖的package包/类
private void applyRewritingInfo() {
    // Rewrite information textView update
    String newText = digits.getText().toString();
    if(accountChooserFilterItem != null && accountChooserFilterItem.isChecked()) {
        if(isDigit) {
            newText = PhoneNumberUtils.stripSeparators(newText);
        }
        rewriteTextInfo.setText(rewriteNumber(newText));
    }else {
        rewriteTextInfo.setText("");
    }
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:13,代码来源:DialerFragment.java

示例4: getContactInfoByAddress

import android.telephony.PhoneNumberUtils; //导入方法依赖的package包/类
/**
 *
 * @param context
 * @param address //phone number as-is
 * @return null if not in contacts. array[0] - Display name, [1] - contactId
 */
public ContactInfo getContactInfoByAddress(Context context, String address) {
    ContactInfo contactInfo;
    if(TextUtils.isEmpty(address)) {
        return new ContactInfo(context.getString(R.string.anonymous), null, null, address);
    }
    if(!PhoneNumber.isPhoneNumber(address))
        return new ContactInfo(address, null, null, null);
    ArrayList<String> phoneVersion=new ArrayList<String>();
    contactInfo=new ContactInfo("", null, null, address);
    String phoneNumber = PhoneNumberUtils.stripSeparators(address);
    if(TextUtils.isEmpty(phoneNumber)) {
        return contactInfo;
    }
    phoneVersion.add(phoneNumber);
    String fPhoneNumber=PhoneNumberUtils.formatNumber(address);
    int index=fPhoneNumber.lastIndexOf('-');
    if(index==-1)
        index=fPhoneNumber.lastIndexOf('.');
    String localPhone=fPhoneNumber.substring(index+1);
    if(localPhone!=null || localPhone.length()!=0) {
        phoneVersion.add(localPhone);
    }
    ContactInfo cInfo;
    for(String phone:phoneVersion) {
        cInfo=lookupContactInfo(context, phone);
        if(cInfo!=null)
            return cInfo;
    }
    return contactInfo;
}
 
开发者ID:ivanovpv,项目名称:darksms,代码行数:37,代码来源:ContactDAO.java

示例5: getContactNameByPhoneNumber2

import android.telephony.PhoneNumberUtils; //导入方法依赖的package包/类
/**
 *
 * @param context
 * @param sourcePhoneNumber //phone number as-is
 * @return null if not in contacts. array[0] - Display name, [1] - contactId
 */
@Deprecated
public String[] getContactNameByPhoneNumber2(Context context, String sourcePhoneNumber) {
    String phoneNumber = PhoneNumberUtils.stripSeparators(sourcePhoneNumber);
    String contactInfo[] = {null, phoneNumber};
    if(phoneNumber==null)
        return contactInfo;
    String[] projection = new String[] {
            ContactsContract.Data.CONTACT_ID,
            ContactsContract.Contacts.DISPLAY_NAME,
            ContactsContract.Contacts.LOOKUP_KEY,
            ContactsContract.Contacts.STARRED,
            ContactsContract.Contacts.CONTACT_STATUS,
            ContactsContract.Contacts.CONTACT_PRESENCE
    };
    String selection = "PHONE_NUMBERS_EQUAL(" +
            ContactsContract.CommonDataKinds.Phone.NUMBER +
            ",?) AND " +
            ContactsContract.Data.MIMETYPE + "='" +
            ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "'";
    String selectionArgs[] = new String[] { phoneNumber };
    Cursor cursor = context.getContentResolver().query(ContactsContract.Data.CONTENT_URI, projection, selection, selectionArgs, null);
    if(cursor!=null && cursor.moveToFirst()) {
        contactInfo = new String[2];
        contactInfo[0] = cursor.getString(0);
        contactInfo[1] = cursor.getString(1);
    }
    cursor.close();
    return contactInfo;
}
 
开发者ID:ivanovpv,项目名称:darksms,代码行数:36,代码来源:ContactDAO.java

示例6: sendCaptcha

import android.telephony.PhoneNumberUtils; //导入方法依赖的package包/类
@Override
public void sendCaptcha() {
    if (mCaptchaRequest == null) {
        mCaptchaRequest = new CaptchaRequest();
    }
    if (mShowingEmailTab) {
        mCaptchaRequest.setSendObject(mEmailField.getText().toString());
        mCaptchaRequest.setRegion("");
    } else {
        String phone = PhoneNumberUtils.stripSeparators(mPhoneField.getText().toString());
        mCaptchaRequest.setSendObject(phone);
        mCaptchaRequest.setRegion(mCountryCodeData.country);
    }
    mSendCaptchaAction.sendCaptchaCode(mCaptchaRequest, mCountryCodeData.countryCode);
}
 
开发者ID:TomeOkin,项目名称:LsPush,代码行数:16,代码来源:CaptchaFragment.java

示例7: isPhoneValid

import android.telephony.PhoneNumberUtils; //导入方法依赖的package包/类
public static boolean isPhoneValid(String phone, String region) {
    if (TextUtils.isEmpty(phone)) {
        return false;
    }
    final String str = PhoneNumberUtils.stripSeparators(phone);
    if (region.equals("CN")) {
        return PHONE_NUMBER_PATTERN.matcher(str).matches();
    }
    return str.length() >= 7;
}
 
开发者ID:TomeOkin,项目名称:LsPush,代码行数:11,代码来源:ValidateUtils.java

示例8: deliver

import android.telephony.PhoneNumberUtils; //导入方法依赖的package包/类
private void deliver(SmsMessageRecord message)
    throws UndeliverableMessageException
{
  if (message.isSecure() || message.isKeyExchange() || message.isEndSession()) {
    throw new UndeliverableMessageException("Trying to send a secure SMS?");
  }

  String recipient = message.getIndividualRecipient().getNumber();

  // See issue #1516 for bug report, and discussion on commits related to #4833 for problems
  // related to the original fix to #1516. This still may not be a correct fix if networks allow
  // SMS/MMS sending to alphanumeric recipients other than email addresses, but should also
  // help to fix issue #3099.
  if (!NumberUtil.isValidEmail(recipient)) {
    recipient = PhoneNumberUtils.stripSeparators(PhoneNumberUtils.convertKeypadLettersToDigits(recipient));
  }

  if (!NumberUtil.isValidSmsOrEmail(recipient)) {
    throw new UndeliverableMessageException("Not a valid SMS destination! " + recipient);
  }

  ArrayList<String> messages                = SmsManager.getDefault().divideMessage(message.getBody().getBody());
  ArrayList<PendingIntent> sentIntents      = constructSentIntents(message.getId(), message.getType(), messages, false);
  ArrayList<PendingIntent> deliveredIntents = constructDeliveredIntents(message.getId(), message.getType(), messages);

  // NOTE 11/04/14 -- There's apparently a bug where for some unknown recipients
  // and messages, this will throw an NPE.  We have no idea why, so we're just
  // catching it and marking the message as a failure.  That way at least it doesn't
  // repeatedly crash every time you start the app.
  try {
    getSmsManagerFor(message.getSubscriptionId()).sendMultipartTextMessage(recipient, null, messages, sentIntents, deliveredIntents);
  } catch (NullPointerException npe) {
    Log.w(TAG, npe);
    Log.w(TAG, "Recipient: " + recipient);
    Log.w(TAG, "Message Parts: " + messages.size());

    try {
      for (int i=0;i<messages.size();i++) {
        getSmsManagerFor(message.getSubscriptionId()).sendTextMessage(recipient, null, messages.get(i),
                                                                      sentIntents.get(i),
                                                                      deliveredIntents == null ? null : deliveredIntents.get(i));
      }
    } catch (NullPointerException npe2) {
      Log.w(TAG, npe);
      throw new UndeliverableMessageException(npe2);
    }
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:49,代码来源:SmsSendJob.java


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