我正在尝试将数字格式化为默认国家/地区代码,我知道该怎么做,但是当我这样做时,会出现一个错误,指出这仅适用于 API 21。我的目标是 API 16。如果我使用旧方法,我收到一条错误消息,说该方法已被弃用?如何在 API 16 上使用该方法?
谢谢!
文档:http://developer.android.com/reference/android/telephony/PhoneNumberUtils.html#FORMAT_NANP
最佳答案
以下示例使用@qbix 提到的已弃用方法。
一个好的做法是检查 sdk 的级别以使用正确的方法:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
yourTextView.setText(PhoneNumberUtils.formatNumber(yourStringPhone, Locale.getDefault().getCountry()));
} else {
yourTextView.setText(PhoneNumberUtils.formatNumber(yourStringPhone)); //Deprecated method
}
关于android - 在 API 16 上使用 PhoneNumberUtils.formatNumber(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34521644/