List of usage examples for android.telecom TelecomManager getPhoneAccount
public PhoneAccount getPhoneAccount(PhoneAccountHandle account)
From source file:Main.java
/** * Extract account color from PhoneAccount object. *///from w ww . ja v a2s . c om public static int getAccountColor(Context context, PhoneAccountHandle accountHandle) { TelecomManager telecomManager = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); final PhoneAccount account = telecomManager.getPhoneAccount(accountHandle); // For single-sim devices the PhoneAccount will be NO_HIGHLIGHT_COLOR by default, so it is // safe to always use the account highlight color. return account == null ? PhoneAccount.NO_HIGHLIGHT_COLOR : account.getHighlightColor(); }
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 www .j av a 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 www .j a 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 w w . jav a2s . com*/ 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.compat.telecom.TelecomManagerCompat.java
/** * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes * resources which can be used in a user interface. * * @param telecomManager the {@link TelecomManager} used for method calls, if possible. * @param account The {@link PhoneAccountHandle}. * @return The {@link PhoneAccount} object or null if it doesn't exist. *///from w w w . j a v a 2 s .co m @Nullable public static PhoneAccount getPhoneAccount(@Nullable TelecomManager telecomManager, @Nullable PhoneAccountHandle accountHandle) { if (telecomManager != null && (CompatUtils.isMethodAvailable(TELECOM_MANAGER_CLASS, "getPhoneAccount", PhoneAccountHandle.class))) { return telecomManager.getPhoneAccount(accountHandle); } return null; }
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. java2 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, 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. j av 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.//from w ww . jav a 2 s . co 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.//from www . j a v a 2s . co 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, 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.cyanogenmod.messaging.quickmessage.QuickMessagePopup.java
/** * display the sim select dialog for multi sim phones *///from www . ja v a 2 s . 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"); }