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:org.sufficientlysecure.keychain.util.FileHelper.java

/**
 * Does the device actually have a ACTION_OPEN_DOCUMENT Intent? Looks like some Android
 * distributions are missing the ACTION_OPEN_DOCUMENT Intent even on Android 4.4,
 * see https://github.com/open-keychain/open-keychain/issues/1625
 *
 * @return True, if the device supports ACTION_OPEN_DOCUMENT. False, otherwise.
 *///from   w  w  w. java 2 s  .co  m
@TargetApi(VERSION_CODES.KITKAT)
private static boolean hasOpenDocumentIntent(Context context) {
    if (hasOpenDocumentIntent == null) {
        PackageManager packageManager = context.getPackageManager();
        List<ResolveInfo> resolveInfoList = packageManager
                .queryIntentActivities(new Intent(Intent.ACTION_OPEN_DOCUMENT), 0);
        hasOpenDocumentIntent = !resolveInfoList.isEmpty();
    }

    return hasOpenDocumentIntent;
}

From source file:com.github.chenxiaolong.dualbootpatcher.FileUtils.java

private static boolean canHandleIntent(PackageManager pm, Intent intent) {
    List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
    return list.size() > 0;
}

From source file:com.ruesga.rview.misc.ActivityHelper.java

@SuppressWarnings("Convert2streamapi")
public static void openUri(Context ctx, Uri uri, boolean excludeRview) {
    try {/*w  w w.  jav  a2 s  .c o m*/
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        intent.putExtra(Constants.EXTRA_FORCE_SINGLE_PANEL, true);
        intent.putExtra(Constants.EXTRA_SOURCE, ctx.getPackageName());

        if (excludeRview) {
            // Use a different url to find all the browsers activities
            Intent test = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.es"));
            PackageManager pm = ctx.getPackageManager();
            List<ResolveInfo> activities = pm.queryIntentActivities(test, PackageManager.MATCH_DEFAULT_ONLY);

            List<Intent> targetIntents = new ArrayList<>();
            for (ResolveInfo ri : activities) {
                if (!ri.activityInfo.packageName.equals(ctx.getPackageName())) {
                    Intent i = new Intent(Intent.ACTION_VIEW, uri);
                    i.setPackage(ri.activityInfo.packageName);
                    i.putExtra(Constants.EXTRA_SOURCE, ctx.getPackageName());
                    i.putExtra(Constants.EXTRA_FORCE_SINGLE_PANEL, true);
                    targetIntents.add(i);
                }
            }

            if (targetIntents.size() == 0) {
                throw new ActivityNotFoundException();
            } else if (targetIntents.size() == 1) {
                ctx.startActivity(targetIntents.get(0));
            } else {
                Intent chooserIntent = Intent.createChooser(intent, ctx.getString(R.string.action_open_with));
                chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
                        targetIntents.toArray(new Parcelable[] {}));
                ctx.startActivity(chooserIntent);
            }
        } else {
            ctx.startActivity(intent);
        }

    } catch (ActivityNotFoundException ex) {
        // Fallback to default browser
        String msg = ctx.getString(R.string.exception_browser_not_found, uri.toString());
        Toast.makeText(ctx, msg, Toast.LENGTH_SHORT).show();
    }
}

From source file:io.hypertrack.sendeta.util.images.EasyImage.java

private static Intent createChooserIntent(Context context, String chooserTitle, boolean showGallery)
        throws IOException {
    Uri outputFileUri = createCameraPictureFile(context);
    List<Intent> cameraIntents = new ArrayList<>();
    Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    PackageManager packageManager = context.getPackageManager();
    List<ResolveInfo> camList = packageManager.queryIntentActivities(captureIntent, 0);
    for (ResolveInfo res : camList) {
        final String packageName = res.activityInfo.packageName;
        final Intent intent = new Intent(captureIntent);
        intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
        intent.setPackage(packageName);//from  ww w. j  a  v  a  2  s.co m
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        cameraIntents.add(intent);
    }
    Intent galleryIntent;

    if (showGallery) {
        galleryIntent = createGalleryIntent();
    } else {
        galleryIntent = createDocumentsIntent();
    }

    Intent chooserIntent = Intent.createChooser(galleryIntent, chooserTitle);
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
            cameraIntents.toArray(new Parcelable[cameraIntents.size()]));

    return chooserIntent;
}

From source file:org.alfresco.mobile.android.application.manager.ActionManager.java

public static boolean launchPDF(Context c, String pdfFile) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(new File(pdfFile)), "application/pdf");

    PackageManager pm = c.getPackageManager();
    List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
    if (activities.size() > 0) {
        c.startActivity(intent);//  www  . j  a  v  a2 s. c  om
    } else {
        return false;
    }

    return true;
}

From source file:library.artaris.cn.library.utils.SystemUtils.java

/**
 * ???/*from   w  w w.  j a  v a  2 s  . c  om*/
 * @param context
 * @return
 */
public static List<ResolveInfo> getShareTargets(Context context) {
    Intent intent = new Intent(Intent.ACTION_SEND, null);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setType("text/plain");
    PackageManager pm = context.getPackageManager();
    return pm.queryIntentActivities(intent, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);
}

From source file:com.alainesp.fan.sanderson.MainActivity.java

/**
 * Is an app that can handle this intent?
 * @param intent The intent to check//from   www  .j  av a  2s. c om
 * @return If the intent can be handle
 */
public static boolean isIntentSafe(Intent intent) {
    // Verify it resolves
    PackageManager packageManager = staticRef.getPackageManager();
    List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);
    return activities.size() > 0;
}

From source file:com.oliversride.wordryo.Utils.java

public static boolean canInstall(Context context, File path) {
    boolean result = false;
    PackageManager pm = context.getPackageManager();
    Intent intent = makeInstallIntent(path);
    List<ResolveInfo> doers = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    result = 0 < doers.size();//from  w w  w .j a va 2 s.  com
    return result;
}

From source file:org.sufficientlysecure.keychain.network.orbot.OrbotHelper.java

public static Intent getOrbotInstallIntent(Context context) {
    final Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(ORBOT_MARKET_URI));

    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> resInfos = pm.queryIntentActivities(intent, 0);

    String foundPackageName = null;
    for (ResolveInfo r : resInfos) {
        Log.i("OrbotHelper", "market: " + r.activityInfo.packageName);
        if (TextUtils.equals(r.activityInfo.packageName, FDROID_PACKAGE_NAME)
                || TextUtils.equals(r.activityInfo.packageName, PLAY_PACKAGE_NAME)) {
            foundPackageName = r.activityInfo.packageName;
            break;
        }/*w ww .j ava 2 s  .c  o  m*/
    }

    if (foundPackageName == null) {
        intent.setData(Uri.parse(ORBOT_FDROID_URI));
    } else {
        intent.setPackage(foundPackageName);
    }
    return intent;
}

From source file:com.pdftron.pdf.utils.ViewerUtils.java

public static Uri openImageIntent(Fragment fragment, int requestCode) {
    // Determine Uri of camera image to save.
    final String fname = "IMG_" + System.currentTimeMillis() + ".jpg";
    File sdImageMainDirectory = new File(fragment.getActivity().getExternalCacheDir(), fname);
    Uri outputFileUri = Uri.fromFile(sdImageMainDirectory);

    // Camera.//from ww  w. j a  v a 2s . com
    final List<Intent> cameraIntents = new ArrayList<>();
    final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    final PackageManager packageManager = fragment.getActivity().getPackageManager();
    final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
    for (ResolveInfo res : listCam) {
        final String packageName = res.activityInfo.packageName;
        final Intent intent = new Intent(captureIntent);
        intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
        intent.setPackage(packageName);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        cameraIntents.add(intent);
    }

    // Filesystem.
    final Intent galleryIntent = new Intent(Intent.ACTION_PICK);
    galleryIntent.setType("image/*");
    //galleryIntent.setAction(Intent.ACTION_GET_CONTENT);

    // Chooser of filesystem options.
    final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source");

    // Add the camera options.
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[] {}));

    fragment.startActivityForResult(chooserIntent, requestCode);
    return outputFileUri;
}