本文整理匯總了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);
}