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:Main.java

public static Boolean isCropAvailable(Activity activity) {
    Log.d(TAG, "[AirImagePickerUtils] isCropAvailable");

    final PackageManager packageManager = activity.getPackageManager();
    Intent intent = getIntentForAction(CROP_ACTION);
    intent.setType("image/*");
    List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);

    Log.d(TAG, "[AirImagePickerUtils] Exiting isCropAvailable");

    return list.size() > 0;
}

From source file:Main.java

/**
 * Find out if K-9 Mail is enabled, i.e. an account was set up.
 *
 * @param context/*  w w w  .j a va2  s.  c  om*/
 *         Used to retrieve the package manager.
 *
 * @return {@code true} if K-9 Mail is enabled, {@code false} otherwise.
 */
public static final boolean isK9Enabled(Context context) {
    PackageManager manager = context.getPackageManager();
    try {
        Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"));
        intent.setPackage(PACKAGE_NAME);
        List<ResolveInfo> results = manager.queryIntentActivities(intent, 0);
        return (results != null && results.size() > 0);
    } catch (Exception e) {
        return false;
    }
}

From source file:Main.java

public static boolean isSlydepayPresent(Context context) {

    final PackageManager packageManager = context.getPackageManager();
    Intent intent = packageManager.getLaunchIntentForPackage("com.dreamoval.slydepay.android.cruise");
    if (intent == null) {
        return false;
    }// w  w  w  .  j ava  2  s.co  m
    List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

From source file:com.mobicage.rogerthat.plugins.messaging.widgets.TextLineWidget.java

private static boolean isSpeechRecognitionActivityPresented(Activity callerActivity) {
    try {/* www.  j  av a 2  s.  c  o  m*/
        PackageManager pm = callerActivity.getPackageManager();
        List<ResolveInfo> activities = pm
                .queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);

        if (activities.size() != 0) {
            return true;
        }
    } catch (Exception e) {
        L.bug(e);
    }
    return false;
}

From source file:com.monmonja.library.utils.PlayServiceUtils.java

public static boolean isSpeechRecognitionActivityPresented(Activity callerActivity) {
    try {//from w  w w.  j  ava  2  s . c o m
        // getting an instance of package manager
        PackageManager pm = callerActivity.getPackageManager();
        // a list of activities, which can process speech recognition Intent
        List activities = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);

        if (activities.size() != 0) { // if list not empty
            return true; // then we can recognize the speech
        }
    } catch (Exception e) {

    }

    return false; // we have no activities to recognize the speech
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.M)
public static List<String> getCustomTabSupportingPackages(Context context) {
    PackageManager pm = context.getPackageManager();
    Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
    // Get all apps that can handle VIEW intents.
    List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, PackageManager.MATCH_ALL);
    List<String> packagesSupportingCustomTabs = new ArrayList<>();
    for (ResolveInfo info : resolvedActivityList) {
        Intent serviceIntent = new Intent();
        serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION);
        serviceIntent.setPackage(info.activityInfo.packageName);
        if (pm.resolveService(serviceIntent, 0) != null) {
            packagesSupportingCustomTabs.add(info.activityInfo.packageName);
        }// w ww  .j av  a2 s.  c  o m
    }
    return packagesSupportingCustomTabs;
}

From source file:Main.java

public static void send(Context context, String path) {

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    PackageManager pm = context.getPackageManager();
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setType("*/*");
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path)));
    List<ResolveInfo> list = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    boolean flag = false;
    for (ResolveInfo info : list) {
        if (info.activityInfo.packageName.toLowerCase().contains("bluetooth")
                || info.activityInfo.name.toLowerCase().contains("bluetooth")) {
            ApplicationInfo appInfo = null;
            try {
                appInfo = pm.getApplicationInfo(info.activityInfo.packageName, PackageManager.GET_META_DATA);
            } catch (PackageManager.NameNotFoundException e) {

            }//from  w w w.j  a  v a  2  s .  c  o m
            if (appInfo != null && (appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0
                    && (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
                flag = true;
                break;
            }
        }
    }
    if (!flag) {
        return;
    }
    context.startActivity(intent);
}

From source file:com.todoroo.astrid.actfm.ActFmCameraModule.java

public static void showPictureLauncher(final Activity activity, final ClearImageCallback clearImageOption) {
    ArrayList<String> options = new ArrayList<String>();

    final Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    PackageManager pm = activity.getPackageManager();

    final boolean cameraAvailable = pm.queryIntentActivities(cameraIntent, 0).size() > 0;
    if (cameraAvailable)
        options.add(activity.getString(R.string.actfm_picture_camera));
    options.add(activity.getString(R.string.actfm_picture_gallery));

    if (clearImageOption != null)
        options.add(activity.getString(R.string.actfm_picture_clear));

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(activity,
            android.R.layout.simple_spinner_dropdown_item, options.toArray(new String[options.size()]));

    DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
        @SuppressWarnings("nls")
        @Override/*from  ww w  . j  a  v  a  2s . c  om*/
        public void onClick(DialogInterface d, int which) {
            if (which == 0 && cameraAvailable) {
                lastTempFile = getTempFile(activity);
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                if (lastTempFile != null) {
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(lastTempFile));
                }
                activity.startActivityForResult(intent, REQUEST_CODE_CAMERA);
            } else if ((which == 1 && cameraAvailable) || (which == 0 && !cameraAvailable)) {
                Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                intent.setType("image/*");
                activity.startActivityForResult(
                        Intent.createChooser(intent, activity.getString(R.string.actfm_TVA_tag_picture)),
                        REQUEST_CODE_PICTURE);
            } else {
                if (clearImageOption != null)
                    clearImageOption.clearImage();
            }
        }
    };

    // show a menu of available options
    new AlertDialog.Builder(activity).setAdapter(adapter, listener).show().setOwnerActivity(activity);
}

From source file:com.github.piasy.safelyandroid.activity.StartActivityDelegate.java

/**
 * this method is from the official guide:
 * http://developer.android.com/training/basics/intents/sending.html#StartActivity
 * *//*w ww  .  j  a v a  2 s.  com*/
private static boolean isIntentSafe(PackageManager packageManager, Intent intent) {
    return !packageManager.queryIntentActivities(intent, 0).isEmpty();
}

From source file:Main.java

public static String getLaunchActivityName(Context context) {
    PackageManager localPackageManager = context.getPackageManager();
    Intent localIntent = new Intent("android.intent.action.MAIN");
    localIntent.addCategory("android.intent.category.LAUNCHER");
    try {//ww w . ja  va 2 s .c o  m
        Iterator<ResolveInfo> localIterator = localPackageManager.queryIntentActivities(localIntent, 0)
                .iterator();
        while (localIterator.hasNext()) {
            ResolveInfo localResolveInfo = localIterator.next();
            if (!localResolveInfo.activityInfo.applicationInfo.packageName
                    .equalsIgnoreCase(context.getPackageName()))
                continue;
            String str = localResolveInfo.activityInfo.name;
            return str;
        }
    } catch (Exception localException) {
        return null;
    }
    return null;
}