Example usage for android.telecom PhoneAccount getAddress

List of usage examples for android.telecom PhoneAccount getAddress

Introduction

In this page you can find the example usage for android.telecom PhoneAccount getAddress.

Prototype

public Uri getAddress() 

Source Link

Document

The address (e.g., a phone number) associated with this PhoneAccount .

Usage

From source file:com.cyanogenmod.messaging.quickmessage.QuickMessagePopup.java

/**
 * display the sim select dialog for multi sim phones
 *//* www .  j a  va2s .c om*/
private void showSimSelector(Activity activity, final ComposeMessageView.OnSimSelectedCallback cb) {
    final TelecomManager telecomMgr = (TelecomManager) activity.getSystemService(Context.TELECOM_SERVICE);
    final List<PhoneAccountHandle> handles = telecomMgr.getCallCapablePhoneAccounts();
    final List<PhoneAccountHandle> filteredHandles = new ArrayList<>();

    //trim out SIP accounts
    for (PhoneAccountHandle handle : handles) {
        PhoneAccount phoneAccount = PhoneUtils.getAccountOrNull(activity, handle);
        if (phoneAccount != null) {
            Uri address = phoneAccount.getAddress();
            if (address != null && !TextUtils.equals(address.getScheme(), PhoneAccount.SCHEME_SIP)) {
                filteredHandles.add(handle);
            }
        }
    }

    final SelectPhoneAccountDialogFragment.SelectPhoneAccountListener listener = new SelectPhoneAccountDialogFragment.SelectPhoneAccountListener() {
        @Override
        public void onPhoneAccountSelected(PhoneAccountHandle selectedAccountHandle, boolean setDefault) {
            // we need the subId and we only have a PhoneAccountHandle
            TelephonyManager telephonyManager = (TelephonyManager) mContext
                    .getSystemService(Context.TELEPHONY_SERVICE);
            Iterator<PhoneAccountHandle> phoneAccounts = telecomMgr.getCallCapablePhoneAccounts()
                    .listIterator();
            int subId = 0; // defaulting to 0, just in case
            while (phoneAccounts.hasNext()) {
                PhoneAccountHandle p = phoneAccounts.next();
                if (p.getId().equals(selectedAccountHandle.getId())) {
                    PhoneAccount phoneAccount = telecomMgr.getPhoneAccount(p);
                    subId = telephonyManager.getSubIdForPhoneAccount(phoneAccount);
                }
            }
            cb.onSimSelected(subId);
        }

        @Override
        public void onDialogDismissed() {
        }
    };

    DialogFragment dialogFragment = SelectPhoneAccountDialogFragment.newInstance(
            R.string.select_phone_account_title, false /* canSetDefault */, filteredHandles, listener);
    dialogFragment.show(activity.getFragmentManager(), "SELECT_PHONE_ACCOUNT_DIALOG_FRAGMENT");
}