Example usage for android.content Context TELECOM_SERVICE

List of usage examples for android.content Context TELECOM_SERVICE

Introduction

In this page you can find the example usage for android.content Context TELECOM_SERVICE.

Prototype

String TELECOM_SERVICE

To view the source code for android.content Context TELECOM_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.telecom.TelecomManager to manage telecom-related features of the device.

Usage

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./* w w w  .j a v  a 2  s.  c om*/
 *
 * @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.cyanogenmod.messaging.quickmessage.QuickMessagePopup.java

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

From source file:com.android.contacts.preference.DisplayOptionsPreferenceFragment.java

@Override
public boolean onPreferenceClick(Preference p) {
    final String prefKey = p.getKey();

    if (KEY_ABOUT.equals(prefKey)) {
        ((ContactsPreferenceActivity) getActivity()).showAboutFragment();
        return true;
    } else if (KEY_IMPORT.equals(prefKey)) {
        ImportDialogFragment.show(getFragmentManager());
        return true;
    } else if (KEY_EXPORT.equals(prefKey)) {
        ExportDialogFragment.show(getFragmentManager(), ContactsPreferenceActivity.class,
                ExportDialogFragment.EXPORT_MODE_ALL_CONTACTS);
        return true;
    } else if (KEY_MY_INFO.equals(prefKey)) {
        if (mHasProfile) {
            final Uri uri = ContentUris.withAppendedId(Contacts.CONTENT_URI, mProfileContactId);
            ImplicitIntentsUtil.startQuickContact(getActivity(), uri, ScreenType.ME_CONTACT);
        } else {/*from www  .java  2  s  .c o m*/
            final Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
            intent.putExtra(mNewLocalProfileExtra, true);
            ImplicitIntentsUtil.startActivityInApp(getActivity(), intent);
        }
        return true;
    } else if (KEY_ACCOUNTS.equals(prefKey)) {
        ImplicitIntentsUtil.startActivityOutsideApp(getContext(),
                ImplicitIntentsUtil.getIntentForAddingAccount());
        return true;
    } else if (KEY_BLOCKED_NUMBERS.equals(prefKey)) {
        final Intent intent = TelecomManagerUtil.createManageBlockedNumbersIntent(
                (TelecomManager) getContext().getSystemService(Context.TELECOM_SERVICE));
        startActivity(intent);
        return true;
    } else if (KEY_CUSTOM_CONTACTS_FILTER.equals(prefKey)) {
        final ContactListFilter filter = ContactListFilterController.getInstance(getContext()).getFilter();
        AccountFilterUtil.startAccountFilterActivityForResult(this, REQUEST_CODE_CUSTOM_CONTACTS_FILTER,
                filter);
    }
    return false;
}

From source file:com.android.contacts.activities.PeopleActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (mDisableOptionItemSelected) {
        return false;
    }//from  ww  w .  j a va 2s .c  om

    switch (item.getItemId()) {
    case android.R.id.home: {
        // The home icon on the action bar is pressed
        if (mActionBarAdapter.isUpShowing()) {
            // "UP" icon press -- should be treated as "back".
            onBackPressed();
        }
        return true;
    }
    case R.id.menu_settings: {
        startActivity(new Intent(this, ContactsPreferenceActivity.class));
        return true;
    }
    case R.id.menu_contacts_filter: {
        AccountFilterUtil.startAccountFilterActivityForResult(this, SUBACTIVITY_ACCOUNT_FILTER,
                mContactListFilterController.getFilter());
        return true;
    }
    case R.id.menu_search: {
        onSearchRequested();
        return true;
    }
    case R.id.menu_share:
        shareSelectedContacts();
        return true;
    case R.id.menu_join:
        joinSelectedContacts();
        return true;
    case R.id.menu_delete:
        deleteSelectedContacts();
        return true;
    case R.id.menu_import_export: {
        showImportExportDialogFragment();
        return true;
    }
    case R.id.menu_clear_frequents: {
        ClearFrequentsDialog.show(getFragmentManager());
        return true;
    }
    case R.id.menu_help:
        HelpUtils.launchHelpAndFeedbackForMainScreen(this);
        return true;
    case R.id.menu_accounts: {
        final Intent intent = new Intent(Settings.ACTION_SYNC_SETTINGS);
        intent.putExtra(Settings.EXTRA_AUTHORITIES, new String[] { ContactsContract.AUTHORITY });
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        ImplicitIntentsUtil.startActivityInAppIfPossible(this, intent);
        return true;
    }
    case R.id.menu_blocked_numbers: {
        final Intent intent = TelecomManagerUtil
                .createManageBlockedNumbersIntent((TelecomManager) getSystemService(Context.TELECOM_SERVICE));
        if (intent != null) {
            startActivity(intent);
        }
        return true;
    }
    case R.id.export_database: {
        final Intent intent = new Intent("com.android.providers.contacts.DUMP_DATABASE");
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        ImplicitIntentsUtil.startActivityOutsideApp(this, intent);
        return true;
    }
    }
    return false;
}

From source file:com.android.dialer.DialtactsFragment.java

private TelecomManager getTelecomManager() {
    return (TelecomManager) getActivity().getSystemService(Context.TELECOM_SERVICE);
}