Example usage for android.content.pm PackageManager queryIntentActivities

List of usage examples for android.content.pm PackageManager queryIntentActivities

Introduction

In this page you can find the example usage for android.content.pm PackageManager queryIntentActivities.

Prototype

public abstract List<ResolveInfo> queryIntentActivities(Intent intent, @ResolveInfoFlags int flags);

Source Link

Document

Retrieve all activities that can be performed for the given intent.

Usage

From source file:com.codeslap.topy.BaseMultiPaneActivity.java

/** {@inheritDoc} */
@Override/*from w  ww .j a va 2s  .co m*/
public void openActivityOrFragment(final Intent intent) {
    final PackageManager pm = getPackageManager();
    List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    for (ResolveInfo resolveInfo : resolveInfoList) {
        final FragmentReplaceInfo fri = onSubstituteFragmentForActivityLaunch(resolveInfo.activityInfo.name);
        if (fri != null) {
            final Bundle arguments = intentToFragmentArguments(intent);
            final FragmentManager fm = getSupportFragmentManager();

            try {
                Fragment fragment = (Fragment) fri.getFragmentClass().newInstance();
                fragment.setArguments(arguments);

                FragmentTransaction ft = fm.beginTransaction();
                ft.replace(fri.getContainerId(), fragment, fri.getFragmentTag());
                onBeforeCommitReplaceFragment(fm, ft, fragment);
                ft.commit();
            } catch (InstantiationException e) {
                throw new IllegalStateException("Error creating new fragment.", e);
            } catch (IllegalAccessException e) {
                throw new IllegalStateException("Error creating new fragment.", e);
            }
            return;
        }
    }
    super.openActivityOrFragment(intent);
}

From source file:com.ipo.wiimote.SpeechRecognizer.java

/**
 * Checks if a recognizer is present on this device
 *//*from   ww  w. j  a v  a2 s.c o  m*/
private boolean IsSpeechRecognizerPresent() {
    PackageManager pm = cordova.getActivity().getPackageManager();
    List activities = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
    return !activities.isEmpty();
}

From source file:com.android.test.uibench.MainActivity.java

protected List<Map<String, Object>> getData(String prefix) {
    List<Map<String, Object>> myData = new ArrayList<>();

    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(CATEGORY_HWUI_TEST);

    PackageManager pm = getPackageManager();
    List<ResolveInfo> list = pm.queryIntentActivities(mainIntent, 0);

    if (null == list)
        return myData;

    String[] prefixPath;/* w w w. ja  v a 2s .  c  om*/
    String prefixWithSlash = prefix;

    if (prefix.equals("")) {
        prefixPath = null;
    } else {
        prefixPath = prefix.split("/");
        prefixWithSlash = prefix + "/";
    }

    int len = list.size();

    Map<String, Boolean> entries = new HashMap<>();

    for (int i = 0; i < len; i++) {
        ResolveInfo info = list.get(i);
        CharSequence labelSeq = info.loadLabel(pm);
        String label = labelSeq != null ? labelSeq.toString() : info.activityInfo.name;

        if (prefixWithSlash.length() == 0 || label.startsWith(prefixWithSlash)) {

            String[] labelPath = label.split("/");

            String nextLabel = prefixPath == null ? labelPath[0] : labelPath[prefixPath.length];

            if ((prefixPath != null ? prefixPath.length : 0) == labelPath.length - 1) {
                addItem(myData, nextLabel,
                        activityIntent(info.activityInfo.applicationInfo.packageName, info.activityInfo.name));
            } else {
                if (entries.get(nextLabel) == null) {
                    addItem(myData, nextLabel,
                            browseIntent(prefix.equals("") ? nextLabel : prefix + "/" + nextLabel));
                    entries.put(nextLabel, true);
                }
            }
        }
    }

    Collections.sort(myData, sDisplayNameComparator);

    return myData;
}

From source file:com.cerema.cloud2.ui.dialog.ShareLinkToDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    mIntent = getArguments().getParcelable(ARG_INTENT);
    String[] packagesToExclude = getArguments().getStringArray(ARG_PACKAGES_TO_EXCLUDE);
    List<String> packagesToExcludeList = Arrays
            .asList(packagesToExclude != null ? packagesToExclude : new String[0]);

    PackageManager pm = getActivity().getPackageManager();
    List<ResolveInfo> activities = pm.queryIntentActivities(mIntent, PackageManager.MATCH_DEFAULT_ONLY);
    Iterator<ResolveInfo> it = activities.iterator();
    ResolveInfo resolveInfo;/*from  w  w  w. j a va 2 s.  co  m*/
    while (it.hasNext()) {
        resolveInfo = it.next();
        if (packagesToExcludeList.contains(resolveInfo.activityInfo.packageName.toLowerCase())) {
            it.remove();
        }
    }

    boolean sendAction = mIntent.getBooleanExtra(Intent.ACTION_SEND, false);

    if (!sendAction) {
        // add activity for copy to clipboard
        Intent copyToClipboardIntent = new Intent(getActivity(), CopyToClipboardActivity.class);
        List<ResolveInfo> copyToClipboard = pm.queryIntentActivities(copyToClipboardIntent, 0);
        if (!copyToClipboard.isEmpty()) {
            activities.add(copyToClipboard.get(0));
        }
    }

    Collections.sort(activities, new ResolveInfo.DisplayNameComparator(pm));
    mAdapter = new ActivityAdapter(getActivity(), pm, activities);

    return createSelector(sendAction);

}

From source file:com.owncloud.android.ui.dialog.ShareLinkToDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    mIntent = getArguments().getParcelable(ARG_INTENT);
    String[] packagesToExclude = getArguments().getStringArray(ARG_PACKAGES_TO_EXCLUDE);
    List<String> packagesToExcludeList = Arrays
            .asList(packagesToExclude != null ? packagesToExclude : new String[0]);
    mFile = getArguments().getParcelable(ARG_FILE_TO_SHARE);

    PackageManager pm = getActivity().getPackageManager();
    List<ResolveInfo> activities = pm.queryIntentActivities(mIntent, PackageManager.MATCH_DEFAULT_ONLY);
    Iterator<ResolveInfo> it = activities.iterator();
    ResolveInfo resolveInfo;/*from   w w w.  j  av  a2  s.c  om*/
    while (it.hasNext()) {
        resolveInfo = it.next();
        if (packagesToExcludeList.contains(resolveInfo.activityInfo.packageName.toLowerCase())) {
            it.remove();
        }
    }

    boolean sendAction = mIntent.getBooleanExtra(Intent.ACTION_SEND, false);

    if (!sendAction) {
        // add activity for copy to clipboard
        Intent copyToClipboardIntent = new Intent(getActivity(), CopyToClipboardActivity.class);
        List<ResolveInfo> copyToClipboard = pm.queryIntentActivities(copyToClipboardIntent, 0);
        if (!copyToClipboard.isEmpty()) {
            activities.add(copyToClipboard.get(0));
        }
    }

    Collections.sort(activities, new ResolveInfo.DisplayNameComparator(pm));
    mAdapter = new ActivityAdapter(getActivity(), pm, activities);

    return createSelector(sendAction);

}

From source file:com.daon.identityx.samplefidoapp.SplashActivity.java

/***
 * Attempt to get the list of UAF Clients on the device and
 * add these to the static list.//from   w w  w . j a  va  2s .c o  m
 *
 */
protected void loadUafClientList() {

    List<ResolveInfo> clientList;
    final Intent intent = new Intent();
    intent.setAction(AndroidClientIntentParameters.intentAction);
    intent.setType(AndroidClientIntentParameters.intentType);

    PackageManager manager = this.getPackageManager();
    clientList = manager.queryIntentActivities(intent, 0);
    UafClientLogUtils.logUafClientActivities(clientList);
    getUafClientList().addAll(clientList);
}

From source file:org.apache.cordova.plugins.speech.SpeechRecognizer.java

/**
 * Checks if a recognizer is present on this device
 *//*from   w ww.j a v  a2s . c o m*/
private boolean IsSpeechRecognizerPresent() {
    PackageManager pm = cordova.getActivity().getPackageManager();
    List<ResolveInfo> activities = pm
            .queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
    return !activities.isEmpty();
}

From source file:net.peterkuterna.android.apps.devoxxfrsched.util.ActivityHelper.java

/**
 * Takes a given intent and either starts a new activity to handle it (the
 * default behavior), or creates/updates a fragment (in the case of a
 * multi-pane activity) that can handle the intent.
 * /*from   w  w w .  j a v  a2s  .  c  o m*/
 * Must be called from the main (UI) thread.
 */
public void openActivityOrFragment(Intent intent) {
    if (mActivity instanceof BaseMultiPaneActivity) {
        BaseMultiPaneActivity multiPaneActivity = (BaseMultiPaneActivity) mActivity;
        final PackageManager pm = multiPaneActivity.getPackageManager();
        List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        for (ResolveInfo resolveInfo : resolveInfoList) {
            final FragmentReplaceInfo fri = multiPaneActivity
                    .onSubstituteFragmentForActivityLaunch(resolveInfo.activityInfo.name);
            if (fri != null) {
                final Bundle arguments = intentToFragmentArguments(intent);
                final FragmentManager fm = multiPaneActivity.getSupportFragmentManager();

                try {
                    Fragment fragment = (Fragment) fri.getFragmentClass().newInstance();
                    fragment.setArguments(arguments);

                    FragmentTransaction ft = fm.beginTransaction();
                    ft.replace(fri.getContainerId(), fragment, fri.getFragmentTag());
                    multiPaneActivity.onBeforeCommitReplaceFragment(fm, ft, fragment);
                    ft.commit();
                    multiPaneActivity.onAfterCommitReplaceFragment(fm, ft, fragment);
                } catch (InstantiationException e) {
                    throw new IllegalStateException("Error creating new fragment.", e);
                } catch (IllegalAccessException e) {
                    throw new IllegalStateException("Error creating new fragment.", e);
                }
                return;
            }
        }
    }
    mActivity.startActivity(intent);
}

From source file:net.peterkuterna.android.apps.devoxxsched.util.ActivityHelper.java

/**
 * Takes a given intent and either starts a new activity to handle it (the
 * default behavior), or creates/updates a fragment (in the case of a
 * multi-pane activity) that can handle the intent.
 * //from   w  w  w.j a v  a 2  s  .  c  om
 * Must be called from the main (UI) thread.
 */
public void openActivityOrFragment(Intent intent) {
    if (mActivity instanceof MultiPaneActivity) {
        MultiPaneActivity multiPaneActivity = (MultiPaneActivity) mActivity;
        final PackageManager pm = multiPaneActivity.getPackageManager();
        List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        for (ResolveInfo resolveInfo : resolveInfoList) {
            final FragmentReplaceInfo fri = multiPaneActivity
                    .onSubstituteFragmentForActivityLaunch(resolveInfo.activityInfo.name);
            if (fri != null) {
                final Bundle arguments = intentToFragmentArguments(intent);
                final FragmentManager fm = multiPaneActivity.getSupportFragmentManager();

                try {
                    Fragment fragment = (Fragment) fri.getFragmentClass().newInstance();
                    fragment.setArguments(arguments);

                    FragmentTransaction ft = fm.beginTransaction();
                    ft.replace(fri.getContainerId(), fragment, fri.getFragmentTag());
                    multiPaneActivity.onBeforeCommitReplaceFragment(fm, ft, fragment);
                    ft.commit();
                    multiPaneActivity.onAfterCommitReplaceFragment(fm, ft, fragment);
                } catch (InstantiationException e) {
                    throw new IllegalStateException("Error creating new fragment.", e);
                } catch (IllegalAccessException e) {
                    throw new IllegalStateException("Error creating new fragment.", e);
                }
                return;
            }
        }
    }
    mActivity.startActivity(intent);

}

From source file:org.alfresco.mobile.android.application.fragments.create.EditorsDialogFragment.java

public Dialog onCreateDialog(Bundle savedInstanceState) {
    AnalyticsHelper.reportScreen(getActivity(), AnalyticsManager.SCREEN_NODE_CREATE_EDITOR);

    int title = R.string.create_document_editor_title;

    LayoutInflater inflater = LayoutInflater.from(getActivity());
    final View v = inflater.inflate(R.layout.sdk_list, null);
    ListView lv = (ListView) v.findViewById(R.id.listView);

    final DocumentTypeRecord documentType = (DocumentTypeRecord) getArguments().get(ARGUMENT_DOCUMENT_TYPE);

    // ACTION_VIEW seems to be the only Public Intent to open and
    // 'eventually' edit a document.
    // ACTION_EDIT doesn't work
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(new File("/sdcard/test" + documentType.extension)),
            documentType.mimetype);/*from   w ww.j  a  v a  2 s.co  m*/
    final PackageManager mgr = getActivity().getPackageManager();
    list = mgr.queryIntentActivities(intent, 0);
    Collections.sort(list, new EditorComparator(getActivity(), true));

    MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity())
            .iconRes(R.drawable.ic_application_logo);

    if (list.isEmpty()) {
        // If there's no 3rd party application able to create, we display a
        // warning message.
        return builder.title(R.string.create_document_editor_not_available)
                .content(R.string.create_document_editor_not_available_description)
                .positiveText(R.string.open_play_store).callback(new MaterialDialog.ButtonCallback() {
                    @Override
                    public void onPositive(MaterialDialog dialog) {
                        ActionUtils.actionDisplayPlayStore(getActivity());
                    }
                }).show();
    } else {
        return builder.title(title).adapter(new EditorAdapter(getActivity(), R.layout.row_single_line, list),
                new MaterialDialog.ListCallback() {
                    @Override
                    public void onSelection(MaterialDialog materialDialog, View view, int position,
                            CharSequence charSequence) {
                        Bundle b = getArguments();
                        b.putParcelable(ARGUMENT_EDITOR, list.get(position));
                        DocumentPropertiesDialogFragment dialogft = DocumentPropertiesDialogFragment
                                .newInstance(b);
                        dialogft.show(getFragmentManager(), DocumentPropertiesDialogFragment.TAG);

                        materialDialog.dismiss();
                    }
                }).show();
    }
}