Example usage for android.telecom TelecomManager getDefaultOutgoingPhoneAccount

List of usage examples for android.telecom TelecomManager getDefaultOutgoingPhoneAccount

Introduction

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

Prototype

@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) 

Source Link

Document

Return the PhoneAccount which will be used to place outgoing calls to addresses with the specified uriScheme .

Usage

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

/**
 * Return the {@link PhoneAccount} which will be used to place outgoing calls to addresses with
 * the specified {@code uriScheme}. This PhoneAccount will always be a member of the
 * list which is returned from invoking {@link TelecomManager#getCallCapablePhoneAccounts()}.
 * The specific account returned depends on the following priorities:
 *
 * 1. If the user-selected default PhoneAccount supports the specified scheme, it will
 * be returned.//  w w  w  .  j a  va2  s . c o  m
 * 2. If there exists only one PhoneAccount that supports the specified scheme, it
 * will be returned.
 *
 * If no PhoneAccount fits the criteria above, this method will return {@code null}.
 *
 * @param telecomManager the {@link TelecomManager} used for method calls, if possible.
 * @param uriScheme The URI scheme.
 * @return The {@link PhoneAccountHandle} corresponding to the account to be used.
 */
@Nullable
public static PhoneAccountHandle getDefaultOutgoingPhoneAccount(@Nullable TelecomManager telecomManager,
        @Nullable String uriScheme) {
    if (telecomManager != null && (CompatUtils.isMarshmallowCompatible() || CompatUtils
            .isMethodAvailable(TELECOM_MANAGER_CLASS, "getDefaultOutgoingPhoneAccount", String.class))) {
        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 null;
        }
        return telecomManager.getDefaultOutgoingPhoneAccount(uriScheme);
    }
    return null;
}