本文整理汇总了Java中android.telephony.PhoneNumberUtils.normalizeNumber方法的典型用法代码示例。如果您正苦于以下问题:Java PhoneNumberUtils.normalizeNumber方法的具体用法?Java PhoneNumberUtils.normalizeNumber怎么用?Java PhoneNumberUtils.normalizeNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.telephony.PhoneNumberUtils
的用法示例。
在下文中一共展示了PhoneNumberUtils.normalizeNumber方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: callNumber
import android.telephony.PhoneNumberUtils; //导入方法依赖的package包/类
/**
* Uses an implicit intent to make the phone call.
* Before calling, checks to see if permission is granted.
*
* @param view View that was clicked.
*/
public void callNumber(View view) {
String normalizedPhoneNumber;
// Find the editText_main view and assign it to editText.
EditText editText = (EditText) findViewById(R.id.editText_main);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
Log.d(TAG, "Running version earlier than Lollipop. Can't normalize number.");
normalizedPhoneNumber = editText.getText().toString();
} else {
normalizedPhoneNumber =
PhoneNumberUtils.normalizeNumber(editText.getText().toString());
}
// Use format with "tel:" and phone number to create phoneNumber.
String phoneNumber = String.format("tel: %s", normalizedPhoneNumber);
// Log the concatenated phone number for dialing.
Log.d(TAG, getString(R.string.dial_number) + phoneNumber);
Toast.makeText(this, getString(R.string.dial_number) + phoneNumber,
Toast.LENGTH_LONG).show();
// Create the intent.
Intent callIntent = new Intent(Intent.ACTION_CALL);
// Set the data for the intent as the phone number.
callIntent.setData(Uri.parse(phoneNumber));
// If package resolves to an app, check for phone permission,
// and send intent.
if (callIntent.resolveActivity(getPackageManager()) != null) {
checkForPhonePermission();
startActivity(callIntent);
} else {
Log.e(TAG, "Can't resolve app for ACTION_CALL Intent.");
}
}
示例2: dial
import android.telephony.PhoneNumberUtils; //导入方法依赖的package包/类
static void dial(final Context context, String number) {
number = PhoneNumberUtils.normalizeNumber(number);
Log.d(TAG, "Dialing phone number: " + number); //NON-NLS
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Required for Android below v7
callIntent.setData(Uri.parse("tel:" + number)); //NON-NLS
try {
context.startActivity(callIntent); // Call dial number
} catch (SecurityException e) {
Log.e(TAG, e.toString());
}
}
示例3: User
import android.telephony.PhoneNumberUtils; //导入方法依赖的package包/类
User(String name, String number, String password, boolean active, boolean caseSensitive) {
this.name = name;
this.number = PhoneNumberUtils.normalizeNumber(number);
this.password = password;
this.active = active;
this.caseSensitive = caseSensitive;
System.out.println(this.number);
}