本文整理汇总了Java中android.telephony.PhoneNumberUtils类的典型用法代码示例。如果您正苦于以下问题:Java PhoneNumberUtils类的具体用法?Java PhoneNumberUtils怎么用?Java PhoneNumberUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PhoneNumberUtils类属于android.telephony包,在下文中一共展示了PhoneNumberUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: format
import android.telephony.PhoneNumberUtils; //导入依赖的package包/类
@Override
public CharSequence format(CharSequence value, int index) {
value = PhoneNumberUtils.formatNumber(value.toString());
Map<String,Set<String>> metadata =
metadataForIndex == null || metadataForIndex.size() <= index ? null : metadataForIndex.get(index);
value = formatMetadata(value, metadata);
return value;
}
示例2: doCallPhoneTo
import android.telephony.PhoneNumberUtils; //导入依赖的package包/类
/**
* 调起系统打电话功能
*/
public void doCallPhoneTo(String phoneNumber) {
if (PhoneNumberUtils.isGlobalPhoneNumber(phoneNumber)) {
if (mayCallPhone()) {
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber));
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE)
!= PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
startActivity(intent);
}
}
}
示例3: loadRecipients
import android.telephony.PhoneNumberUtils; //导入依赖的package包/类
/**
* For a given address type, extract the recipients from the headers.
*
* @param addressType can be PduHeaders.FROM or PduHeaders.TO
* @param recipients a HashSet that is loaded with the recipients from the FROM or TO headers
* @param addressMap a HashMap of the addresses from the ADDRESS_FIELDS header
* @param excludeMyNumber if true, the number of this phone will be excluded from recipients
*/
private void loadRecipients(int addressType, HashSet<String> recipients,
HashMap<Integer, EncodedStringValue[]> addressMap, boolean excludeMyNumber) {
EncodedStringValue[] array = addressMap.get(addressType);
if (array == null) {
return;
}
// If the TO recipients is only a single address, then we can skip loadRecipients when
// we're excluding our own number because we know that address is our own.
if (excludeMyNumber && array.length == 1) {
return;
}
String myNumber = excludeMyNumber ? mTelephonyManager.getLine1Number() : null;
for (EncodedStringValue v : array) {
if (v != null) {
String number = v.getString();
if ((myNumber == null || !PhoneNumberUtils.compare(number, myNumber)) &&
!recipients.contains(number)) {
// Only add numbers which aren't my own number.
recipients.add(number);
}
}
}
}
示例4: getNormalizedAddress
import android.telephony.PhoneNumberUtils; //导入依赖的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);
}
}
示例5: enterState
import android.telephony.PhoneNumberUtils; //导入依赖的package包/类
private void enterState(int state) {
switch(state) {
case LOADING:
mActionBar.setTitle(R.string.bt_card_details);
mViewSwitcher.setDisplayedChild(0);
break;
case CARD_ENTRY:
mActionBar.setTitle(R.string.bt_card_details);
mAddCardView.setVisibility(VISIBLE);
break;
case DETAILS_ENTRY:
mActionBar.setTitle(R.string.bt_card_details);
mEditCardView.setCardNumber(mAddCardView.getCardForm().getCardNumber());
mEditCardView.useUnionPay(this, mUnionPayCard, mUnionPayDebitCard);
mEditCardView.setVisibility(VISIBLE);
break;
case ENROLLMENT_ENTRY:
mActionBar.setTitle(R.string.bt_confirm_enrollment);
mEnrollmentCardView.setPhoneNumber(
PhoneNumberUtils.formatNumber(mEditCardView.getCardForm().getCountryCode() +
mEditCardView.getCardForm().getMobileNumber()));
mEnrollmentCardView.setVisibility(VISIBLE);
break;
}
}
示例6: retrieveFiles
import android.telephony.PhoneNumberUtils; //导入依赖的package包/类
private void retrieveFiles(){
RealmResults<CallHistory> result = myRealm.where(CallHistory.class)
.isNotNull(CallHistory.kCOL_FILE_PATH)
.findAllSorted(CallHistory.kCOL_DATE_TIME, Sort.DESCENDING);
arrayFilePaths.clear();
arrayCalls.clear();
if (result.size() > 0) {
for(CallHistory c:result) {
arrayFilePaths.add(PhoneNumberUtils.formatNumber(c.phoneNumber) + " " + getDate(c.dateTime, "d/MM/yyyy HH:mm:ss"));
arrayCalls.add(c);
}
}
if (adapter != null) {
adapter.notifyDataSetChanged();
if (arrayCalls.size() > 0 && !hasPlayerSetup){
AudioWife.getInstance().init(CallReceiverActivity.this, Uri.parse(arrayCalls.get(0).getFilePath())).useDefaultUi(llMediaPlayer, getLayoutInflater());
hasPlayerSetup = true;
}
}
}
示例7: getFormattedFullNumber
import android.telephony.PhoneNumberUtils; //导入依赖的package包/类
/**
* This function combines selected country code from CCP and carrier number from @param editTextCarrierNumber
* This will return formatted number.
*
* @return Full number is countryCode + carrierNumber i.e countryCode= 91 and carrier number= 8866667722, this will return "918866667722"
*/
public String getFormattedFullNumber() {
String formattedFullNumber;
Phonenumber.PhoneNumber phoneNumber;
if (editText_registeredCarrierNumber != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
formattedFullNumber = PhoneNumberUtils.formatNumber(getFullNumberWithPlus(), getSelectedCountryCode());
} else {
formattedFullNumber = PhoneNumberUtils.formatNumber(getFullNumberWithPlus());
}
} else {
formattedFullNumber = getSelectedCountry().getPhoneCode();
Log.w(TAG, "EditText for carrier number is not registered. Register it using registerCarrierNumberEditText() before getFullNumber() or setFullNumber().");
}
return formattedFullNumber;
}
示例8: encode
import android.telephony.PhoneNumberUtils; //导入依赖的package包/类
@Override
public String[] encode(Iterable<String> names,
String organization,
Iterable<String> addresses,
Iterable<String> phones,
Iterable<String> emails,
String url,
String note) {
StringBuilder newContents = new StringBuilder(100);
StringBuilder newDisplayContents = new StringBuilder(100);
newContents.append("BEGIN:VCARD").append(TERMINATOR);
appendUpToUnique(newContents, newDisplayContents, "N", names, 1, null);
append(newContents, newDisplayContents, "ORG", organization);
appendUpToUnique(newContents, newDisplayContents, "ADR", addresses, 1, null);
appendUpToUnique(newContents, newDisplayContents, "TEL", phones, Integer.MAX_VALUE, new Formatter() {
@Override
public String format(String source) {
return PhoneNumberUtils.formatNumber(source);
}
});
appendUpToUnique(newContents, newDisplayContents, "EMAIL", emails, Integer.MAX_VALUE, null);
append(newContents, newDisplayContents, "URL", url);
append(newContents, newDisplayContents, "NOTE", note);
newContents.append("END:VCARD").append(TERMINATOR);
return new String[] { newContents.toString(), newDisplayContents.toString() };
}
示例9: getUserPosition
import android.telephony.PhoneNumberUtils; //导入依赖的package包/类
@Nullable
private static ListIterator<User> getUserPosition(Context context, User user) {
ArrayList<User> users = getUsers(context);
if (users != null) {
ListIterator<User> iterator;
iterator = users.listIterator();
while (iterator.hasNext()) {
if (PhoneNumberUtils.compare(iterator.next().number, user.number)) {
return iterator;
}
}
}
return null;
}
示例10: encode
import android.telephony.PhoneNumberUtils; //导入依赖的package包/类
@Override
public String[] encode(Iterable<String> names,
String organization,
Iterable<String> addresses,
Iterable<String> phones,
Iterable<String> emails,
Iterable<String> urls,
String note) {
StringBuilder newContents = new StringBuilder(100);
newContents.append("BEGIN:VCARD").append(TERMINATOR);
newContents.append("VERSION:3.0").append(TERMINATOR);
StringBuilder newDisplayContents = new StringBuilder(100);
appendUpToUnique(newContents, newDisplayContents, "N", names, 1, null);
append(newContents, newDisplayContents, "ORG", organization);
appendUpToUnique(newContents, newDisplayContents, "ADR", addresses, 1, null);
appendUpToUnique(newContents, newDisplayContents, "TEL", phones, Integer.MAX_VALUE, new Formatter() {
@Override
public String format(String source) {
return PhoneNumberUtils.formatNumber(source);
}
});
appendUpToUnique(newContents, newDisplayContents, "EMAIL", emails, Integer.MAX_VALUE, null);
appendUpToUnique(newContents, newDisplayContents, "URL", urls, Integer.MAX_VALUE, null);
append(newContents, newDisplayContents, "NOTE", note);
newContents.append("END:VCARD").append(TERMINATOR);
return new String[] { newContents.toString(), newDisplayContents.toString() };
}
示例11: getDisplayContents
import android.telephony.PhoneNumberUtils; //导入依赖的package包/类
@Override
public CharSequence getDisplayContents() {
SMSParsedResult smsResult = (SMSParsedResult) getResult();
String[] rawNumbers = smsResult.getNumbers();
String[] formattedNumbers = new String[rawNumbers.length];
for (int i = 0; i < rawNumbers.length; i++) {
formattedNumbers[i] = PhoneNumberUtils.formatNumber(rawNumbers[i]);
}
StringBuilder contents = new StringBuilder(50);
ParsedResult.maybeAppend(formattedNumbers, contents);
ParsedResult.maybeAppend(smsResult.getSubject(), contents);
ParsedResult.maybeAppend(smsResult.getBody(), contents);
return contents.toString();
}
示例12: isValidAddress
import android.telephony.PhoneNumberUtils; //导入依赖的package包/类
private boolean isValidAddress(String number, boolean isMms) {
/*if (isMms) {
return MessageUtils.isValidMmsAddress(number);
} else {*/
// TODO: PhoneNumberUtils.isWellFormedSmsAddress() only check if the number is a valid
// GSM SMS address. If the address contains a dialable char, it considers it a well
// formed SMS addr. CDMA doesn't work that way and has a different parser for SMS
// address (see CdmaSmsAddress.parse(String address)). We should definitely fix this!!!
return PhoneNumberUtils.isWellFormedSmsAddress(number);
}
示例13: isNumberAddress
import android.telephony.PhoneNumberUtils; //导入依赖的package包/类
@VisibleForTesting
static boolean isNumberAddress(@NonNull String number) {
if (number.contains("@")) return false;
if (GroupUtil.isEncodedGroup(number)) return false;
final String networkNumber = PhoneNumberUtils.extractNetworkPortion(number);
if (TextUtils.isEmpty(networkNumber)) return false;
if (networkNumber.length() < 3) return false;
return PhoneNumberUtils.isWellFormedSmsAddress(number);
}
示例14: insertMessageOutbox
import android.telephony.PhoneNumberUtils; //导入依赖的package包/类
protected long insertMessageOutbox(long threadId, OutgoingTextMessage message,
long type, boolean forceSms, long date)
{
if (message.isKeyExchange()) type |= Types.KEY_EXCHANGE_BIT;
else if (message.isSecureMessage()) type |= (Types.SECURE_MESSAGE_BIT | Types.PUSH_MESSAGE_BIT);
else if (message.isEndSession()) type |= Types.END_SESSION_BIT;
if (forceSms) type |= Types.MESSAGE_FORCE_SMS_BIT;
String address = message.getRecipients().getPrimaryRecipient().getNumber();
ContentValues contentValues = new ContentValues(6);
contentValues.put(ADDRESS, PhoneNumberUtils.formatNumber(address));
contentValues.put(THREAD_ID, threadId);
contentValues.put(BODY, message.getMessageBody());
contentValues.put(DATE_RECEIVED, System.currentTimeMillis());
contentValues.put(DATE_SENT, date);
contentValues.put(READ, 1);
contentValues.put(TYPE, type);
contentValues.put(SUBSCRIPTION_ID, message.getSubscriptionId());
contentValues.put(EXPIRES_IN, message.getExpiresIn());
try {
contentValues.put(RECEIPT_COUNT, earlyReceiptCache.remove(date, canonicalizeNumber(context, address)));
} catch (InvalidNumberException e) {
Log.w(TAG, e);
}
SQLiteDatabase db = databaseHelper.getWritableDatabase();
long messageId = db.insert(TABLE_NAME, ADDRESS, contentValues);
DatabaseFactory.getThreadDatabase(context).update(threadId, true);
DatabaseFactory.getThreadDatabase(context).setLastSeen(threadId);
notifyConversationListeners(threadId);
jobManager.add(new TrimThreadJob(context, threadId));
return messageId;
}
示例15: parseBracketedNumber
import android.telephony.PhoneNumberUtils; //导入依赖的package包/类
private static String parseBracketedNumber(String recipient) throws RecipientFormattingException {
int begin = recipient.indexOf('<');
int end = recipient.indexOf('>');
String value = recipient.substring(begin + 1, end);
if (PhoneNumberUtils.isWellFormedSmsAddress(value))
return value;
else
throw new RecipientFormattingException("Bracketed value: " + value + " is not valid.");
}