當前位置: 首頁>>代碼示例>>Java>>正文


Java PhoneNumberUtils.normalizeNumber方法代碼示例

本文整理匯總了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.");
    }
}
 
開發者ID:google-developer-training,項目名稱:android-fundamentals-phone-sms,代碼行數:37,代碼來源:MainActivity.java

示例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());
    }
}
 
開發者ID:ArcticLabs,項目名稱:Opendoor,代碼行數:16,代碼來源:DoorPhone.java

示例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);
}
 
開發者ID:ArcticLabs,項目名稱:Opendoor,代碼行數:10,代碼來源:User.java


注:本文中的android.telephony.PhoneNumberUtils.normalizeNumber方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。