本文整理汇总了Java中android.telephony.PhoneNumberUtils.formatNumber方法的典型用法代码示例。如果您正苦于以下问题:Java PhoneNumberUtils.formatNumber方法的具体用法?Java PhoneNumberUtils.formatNumber怎么用?Java PhoneNumberUtils.formatNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.telephony.PhoneNumberUtils
的用法示例。
在下文中一共展示了PhoneNumberUtils.formatNumber方法的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: 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;
}
示例3: 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();
}
示例4: formatNameAndNumber
import android.telephony.PhoneNumberUtils; //导入方法依赖的package包/类
public static String formatNameAndNumber(String name, String number) {
// Format like this: Mike Cleron <(650) 555-1234>
// Erick Tseng <(650) 555-1212>
// Tutankhamun <[email protected]>
// (408) 555-1289
String formattedNumber = PhoneNumberUtils.formatNumber(number);
if (!TextUtils.isEmpty(name) && !name.equals(number)) {
return name + " <" + formattedNumber + ">";
} else {
return formattedNumber;
}
}
示例5: buildNameAndNumber
import android.telephony.PhoneNumberUtils; //导入方法依赖的package包/类
public static String buildNameAndNumber(String name, String number) {
// Format like this: Mike Cleron <(650) 555-1234>
// Erick Tseng <(650) 555-1212>
// (408) 555-1289
if (!TextUtils.isEmpty(name) &&
!name.equals(number)) {
return name + " <" + PhoneNumberUtils.formatNumber(number) + ">";
} else {
return PhoneNumberUtils.formatNumber(number);
}
}
示例6: 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;
}
示例7: 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();
}
示例8: 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();
}
示例9: getDisplayContents
import android.telephony.PhoneNumberUtils; //导入方法依赖的package包/类
@Override
public CharSequence getDisplayContents() {
SMSParsedResult smsResult = (SMSParsedResult) getResult();
StringBuilder contents = new StringBuilder(50);
String[] rawNumbers = smsResult.getNumbers();
String[] formattedNumbers = new String[rawNumbers.length];
for (int i = 0; i < rawNumbers.length; i++) {
formattedNumbers[i] = PhoneNumberUtils.formatNumber(rawNumbers[i]);
}
ParsedResult.maybeAppend(formattedNumbers, contents);
ParsedResult.maybeAppend(smsResult.getSubject(), contents);
ParsedResult.maybeAppend(smsResult.getBody(), contents);
return contents.toString();
}
示例10: formatNumber
import android.telephony.PhoneNumberUtils; //导入方法依赖的package包/类
public static String formatNumber(String number) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return PhoneNumberUtils.formatNumber(number, Locale.getDefault().getCountry());
} else {
//Deprecated method
//noinspection deprecation
return PhoneNumberUtils.formatNumber(number);
}
}
示例11: getDisplayContents
import android.telephony.PhoneNumberUtils; //导入方法依赖的package包/类
@Override
public CharSequence getDisplayContents() {
String contents = getResult().getDisplayResult();
contents = contents.replace("\r", "");
return PhoneNumberUtils.formatNumber(contents);
}
示例12: getDisplayContents
import android.telephony.PhoneNumberUtils; //导入方法依赖的package包/类
@Override
public CharSequence getDisplayContents() {
String contents = getResult().getDisplayResult();
contents = contents.replace("\r", "");
return PhoneNumberUtils.formatNumber(contents);
}
示例13: encodeQRCodeContents
import android.telephony.PhoneNumberUtils; //导入方法依赖的package包/类
private void encodeQRCodeContents(Intent intent, String type) {
switch (type) {
case Contents.Type.TEXT:
String textData = intent.getStringExtra(Intents.Encode.DATA);
if (textData != null && !textData.isEmpty()) {
contents = textData;
displayContents = textData;
title = activity.getString(R.string.contents_text);
}
break;
case Contents.Type.EMAIL:
String emailData = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA));
if (emailData != null) {
contents = "mailto:" + emailData;
displayContents = emailData;
title = activity.getString(R.string.contents_email);
}
break;
case Contents.Type.PHONE:
String phoneData = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA));
if (phoneData != null) {
contents = "tel:" + phoneData;
displayContents = PhoneNumberUtils.formatNumber(phoneData);
title = activity.getString(R.string.contents_phone);
}
break;
case Contents.Type.SMS:
String smsData = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA));
if (smsData != null) {
contents = "sms:" + smsData;
displayContents = PhoneNumberUtils.formatNumber(smsData);
title = activity.getString(R.string.contents_sms);
}
break;
case Contents.Type.CONTACT:
Bundle contactBundle = intent.getBundleExtra(Intents.Encode.DATA);
if (contactBundle != null) {
String name = contactBundle.getString(ContactsContract.Intents.Insert.NAME);
String organization = contactBundle.getString(ContactsContract.Intents.Insert.COMPANY);
String address = contactBundle.getString(ContactsContract.Intents.Insert.POSTAL);
List<String> phones = getAllBundleValues(contactBundle, Contents.PHONE_KEYS);
List<String> phoneTypes = getAllBundleValues(contactBundle, Contents.PHONE_TYPE_KEYS);
List<String> emails = getAllBundleValues(contactBundle, Contents.EMAIL_KEYS);
String url = contactBundle.getString(Contents.URL_KEY);
List<String> urls = url == null ? null : Collections.singletonList(url);
String note = contactBundle.getString(Contents.NOTE_KEY);
ContactEncoder encoder = useVCard ? new VCardContactEncoder() : new MECARDContactEncoder();
String[] encoded = encoder.encode(Collections.singletonList(name), organization,
Collections.singletonList(address), phones, phoneTypes, emails, urls, note);
// Make sure we've encoded at least one field.
if (!encoded[1].isEmpty()) {
contents = encoded[0];
displayContents = encoded[1];
title = activity.getString(R.string.contents_contact);
}
}
break;
case Contents.Type.LOCATION:
Bundle locationBundle = intent.getBundleExtra(Intents.Encode.DATA);
if (locationBundle != null) {
// These must use Bundle.getFloat(), not getDouble(), it's part
// of the API.
float latitude = locationBundle.getFloat("LAT", Float.MAX_VALUE);
float longitude = locationBundle.getFloat("LONG", Float.MAX_VALUE);
if (latitude != Float.MAX_VALUE && longitude != Float.MAX_VALUE) {
contents = "geo:" + latitude + ',' + longitude;
displayContents = latitude + "," + longitude;
title = activity.getString(R.string.contents_location);
}
}
break;
}
}
示例14: getDisplayContents
import android.telephony.PhoneNumberUtils; //导入方法依赖的package包/类
@Override
public CharSequence getDisplayContents() {
String contents = getResult().getDisplayResult();
contents = contents.replace("\r", "");
return PhoneNumberUtils.formatNumber(contents);
}
示例15: formatNumber
import android.telephony.PhoneNumberUtils; //导入方法依赖的package包/类
/**
* Format a phone number based on the number's country code, falling
* back to the format defined by the user's current locale. This is
* to replace calling {@link PhoneNumberUtils#formatNumber(String)},
* which was deprecated in the LOLLIPOP release.
*
* @see PhoneNumberUtils#formatNumber(String, String)
* @param number The phone number to be formatted
* @return The phone number, formatted based on the country code or
* user's locale.
*/
public static String formatNumber(String number) {
return PhoneNumberUtils.formatNumber(number, Locale.getDefault().getCountry());
}