Example usage for android.telephony TelephonyManager getSubIdForPhoneAccount

List of usage examples for android.telephony TelephonyManager getSubIdForPhoneAccount

Introduction

In this page you can find the example usage for android.telephony TelephonyManager getSubIdForPhoneAccount.

Prototype

@UnsupportedAppUsage
public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) 

Source Link

Document

Returns the subscription ID for the given phone account.

Usage

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

/**
 * display the sim select dialog for multi sim phones
 *//*from w w w .  ja  v  a  2 s .  com*/
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");
}