Example usage for android.telecom TelecomManager getCallCapablePhoneAccounts

List of usage examples for android.telecom TelecomManager getCallCapablePhoneAccounts

Introduction

In this page you can find the example usage for android.telecom TelecomManager getCallCapablePhoneAccounts.

Prototype

@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public List<PhoneAccountHandle> getCallCapablePhoneAccounts() 

Source Link

Document

Returns a list of PhoneAccountHandle s which can be used to make and receive phone calls.

Usage

From source file:Main.java

/**
 * Retrieve the account metadata, but if the account does not exist or the device has only a
 * single registered and enabled account, return null.
 *///from w w w .j ava  2s.  c o  m
static PhoneAccount getAccountOrNull(Context context, PhoneAccountHandle accountHandle) {
    TelecomManager telecomManager = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
    final PhoneAccount account = telecomManager.getPhoneAccount(accountHandle);
    if (telecomManager.getCallCapablePhoneAccounts().size() <= 1) {
        return null;
    }
    return account;
}

From source file:Main.java

public static boolean isVideoEnabled(Context context) {

    if (true) {//from ww  w  .  ja v  a 2  s . c  o  m
        return true;
    }
    TelecomManager telecommMgr = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
    if (telecommMgr == null) {
        return false;
    }
    List<PhoneAccountHandle> phoneAccountHandles = telecommMgr.getCallCapablePhoneAccounts();
    for (PhoneAccountHandle handle : phoneAccountHandles) {
        final PhoneAccount phoneAccount = telecommMgr.getPhoneAccount(handle);
        if (hasCapability(phoneAccount, PhoneAccount.CAPABILITY_VIDEO_CALLING)) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

/**
 * Return a list of phone accounts that are subscription/SIM accounts.
 *//*w ww . j ava  2  s  .c  o m*/
public static List<PhoneAccountHandle> getSubscriptionPhoneAccounts(Context context) {
    final TelecomManager telecomManager = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);

    List<PhoneAccountHandle> subscriptionAccountHandles = new ArrayList<PhoneAccountHandle>();
    List<PhoneAccountHandle> accountHandles = telecomManager.getCallCapablePhoneAccounts();
    for (PhoneAccountHandle accountHandle : accountHandles) {
        PhoneAccount account = telecomManager.getPhoneAccount(accountHandle);
        if (account.hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)) {
            subscriptionAccountHandles.add(accountHandle);
        }
    }
    return subscriptionAccountHandles;
}

From source file:com.mobileglobe.android.customdialer.common.CallUtil.java

/**
 * Determines if one of the call capable phone accounts defined supports calling with a subject
 * specified./*from w  w  w.  j ava 2  s.com*/
 *
 * @param context The context.
 * @return {@code true} if one of the call capable phone accounts supports calling with a
 *      subject specified, {@code false} otherwise.
 */
@RequiresApi(api = Build.VERSION_CODES.M)
public static boolean isCallWithSubjectSupported(Context context) {
    if (!PermissionsUtil.hasPermission(context, android.Manifest.permission.READ_PHONE_STATE)
            || !CompatUtils.isCallSubjectCompatible()) {
        return false;
    }
    TelecomManager telecommMgr = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
    if (telecommMgr == null) {
        return false;
    }

    if (ActivityCompat.checkSelfPermission(context,
            Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return false;
    }
    List<PhoneAccountHandle> accountHandles = telecommMgr.getCallCapablePhoneAccounts();
    for (PhoneAccountHandle accountHandle : accountHandles) {
        PhoneAccount account = telecommMgr.getPhoneAccount(accountHandle);
        if (account != null && account.hasCapabilities(PhoneAccount.CAPABILITY_CALL_SUBJECT)) {
            return true;
        }
    }
    return false;
}

From source file:com.mobileglobe.android.simpledialer.common.CallUtil.java

/**
 * Determines if one of the call capable phone accounts defined supports calling with a subject
 * specified./*from   w w  w .ja v  a  2  s  .  co  m*/
 *
 * @param context The context.
 * @return {@code true} if one of the call capable phone accounts supports calling with a
 *      subject specified, {@code false} otherwise.
 */
@RequiresApi(api = Build.VERSION_CODES.M)
public static boolean isCallWithSubjectSupported(Context context) {
    if (!PermissionsUtil.hasPermission(context, Manifest.permission.READ_PHONE_STATE)
            || !CompatUtils.isCallSubjectCompatible()) {
        return false;
    }
    TelecomManager telecommMgr = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
    if (telecommMgr == null) {
        return false;
    }

    if (ActivityCompat.checkSelfPermission(context,
            Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return false;
    }
    List<PhoneAccountHandle> accountHandles = telecommMgr.getCallCapablePhoneAccounts();
    for (PhoneAccountHandle accountHandle : accountHandles) {
        PhoneAccount account = telecommMgr.getPhoneAccount(accountHandle);
        if (account != null && account.hasCapabilities(PhoneAccount.CAPABILITY_CALL_SUBJECT)) {
            return true;
        }
    }
    return false;
}

From source file:com.mobileglobe.android.customdialer.common.CallUtil.java

/**
 * Determines if video calling is available, and if so whether presence checking is available
 * as well.// w w w .j  a  v a 2 s.  c  o  m
 *
 * Returns a bitmask with {@link #VIDEO_CALLING_ENABLED} to indicate that video calling is
 * available, and {@link #VIDEO_CALLING_PRESENCE} if presence indication is also available.
 *
 * @param context The context
 * @return A bit-mask describing the current video capabilities.
 */
@RequiresApi(api = Build.VERSION_CODES.M)
public static int getVideoCallingAvailability(Context context) {
    if (!PermissionsUtil.hasPermission(context, android.Manifest.permission.READ_PHONE_STATE)
            || !CompatUtils.isVideoCompatible()) {
        return VIDEO_CALLING_DISABLED;
    }
    TelecomManager telecommMgr = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
    if (telecommMgr == null) {
        return VIDEO_CALLING_DISABLED;
    }

    if (ActivityCompat.checkSelfPermission(context,
            Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return 0;
    }
    List<PhoneAccountHandle> accountHandles = telecommMgr.getCallCapablePhoneAccounts();
    for (PhoneAccountHandle accountHandle : accountHandles) {
        PhoneAccount account = telecommMgr.getPhoneAccount(accountHandle);
        if (account != null) {
            if (account.hasCapabilities(PhoneAccount.CAPABILITY_VIDEO_CALLING)) {
                // Builds prior to N do not have presence support.
                if (!CompatUtils.isVideoPresenceCompatible()) {
                    return VIDEO_CALLING_ENABLED;
                }

                int videoCapabilities = VIDEO_CALLING_ENABLED;
                if (account
                        .hasCapabilities(PhoneAccountSdkCompat.CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) {
                    videoCapabilities |= VIDEO_CALLING_PRESENCE;
                }
                return videoCapabilities;
            }
        }
    }
    return VIDEO_CALLING_DISABLED;
}

From source file:com.mobileglobe.android.simpledialer.common.CallUtil.java

/**
 * Determines if video calling is available, and if so whether presence checking is available
 * as well./* w  w w  .  j  ava  2s.c  om*/
 *
 * Returns a bitmask with {@link #VIDEO_CALLING_ENABLED} to indicate that video calling is
 * available, and {@link #VIDEO_CALLING_PRESENCE} if presence indication is also available.
 *
 * @param context The context
 * @return A bit-mask describing the current video capabilities.
 */
@RequiresApi(api = Build.VERSION_CODES.M)
public static int getVideoCallingAvailability(Context context) {
    if (!PermissionsUtil.hasPermission(context, Manifest.permission.READ_PHONE_STATE)
            || !CompatUtils.isVideoCompatible()) {
        return VIDEO_CALLING_DISABLED;
    }
    TelecomManager telecommMgr = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
    if (telecommMgr == null) {
        return VIDEO_CALLING_DISABLED;
    }

    if (ActivityCompat.checkSelfPermission(context,
            Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return 0;
    }
    List<PhoneAccountHandle> accountHandles = telecommMgr.getCallCapablePhoneAccounts();
    for (PhoneAccountHandle accountHandle : accountHandles) {
        PhoneAccount account = telecommMgr.getPhoneAccount(accountHandle);
        if (account != null) {
            if (account.hasCapabilities(PhoneAccount.CAPABILITY_VIDEO_CALLING)) {
                // Builds prior to N do not have presence support.
                if (!CompatUtils.isVideoPresenceCompatible()) {
                    return VIDEO_CALLING_ENABLED;
                }

                int videoCapabilities = VIDEO_CALLING_ENABLED;
                if (account
                        .hasCapabilities(PhoneAccountSdkCompat.CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) {
                    videoCapabilities |= VIDEO_CALLING_PRESENCE;
                }
                return videoCapabilities;
            }
        }
    }
    return VIDEO_CALLING_DISABLED;
}

From source file:com.mobileglobe.android.customdialer.common.compat.telecom.TelecomManagerCompat.java

/**
 * Returns a list of {@link PhoneAccountHandle}s which can be used to make and receive phone
 * calls. The returned list includes only those accounts which have been explicitly enabled
 * by the user./*  w  w  w . j av a2  s.c  o m*/
 *
 * @param telecomManager the {@link TelecomManager} used for method calls, if possible.
 * @return A list of PhoneAccountHandle objects.
 */
public static List<PhoneAccountHandle> getCallCapablePhoneAccounts(@Nullable TelecomManager telecomManager) {
    if (telecomManager != null && (CompatUtils.isMarshmallowCompatible()
            || CompatUtils.isMethodAvailable(TELECOM_MANAGER_CLASS, "getCallCapablePhoneAccounts"))) {
        if (ActivityCompat.checkSelfPermission(DialerApplication.getContext(),
                Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return new ArrayList<>();
        }
        return telecomManager.getCallCapablePhoneAccounts();
    }
    return new ArrayList<>();
}

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

/**
 * display the sim select dialog for multi sim phones
 *///w  w  w. j  av a2s  .  c o m
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");
}