Example usage for android.content.pm PackageManager MATCH_DEFAULT_ONLY

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

Introduction

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

Prototype

int MATCH_DEFAULT_ONLY

To view the source code for android.content.pm PackageManager MATCH_DEFAULT_ONLY.

Click Source Link

Document

Resolution and querying flag: if set, only filters that support the android.content.Intent#CATEGORY_DEFAULT will be considered for matching.

Usage

From source file:Main.java

public static String getLauncherPackageName(Context context) {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    return resolveInfo.activityInfo.packageName;
}

From source file:Main.java

public static boolean isIntentAvailable(Context context, String action) {
    final PackageManager packageManager = context.getPackageManager();
    final Intent intent = new Intent(action);
    List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

From source file:Main.java

public static boolean isCallable(Context context, String url) {
    String mimeTypeExtension = URLConnection.guessContentTypeFromName(url);

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.parse(url), mimeTypeExtension);
    List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

From source file:Main.java

private static boolean isIntentAvailable(Intent intent, Context context) {
    if (intent == null) {
        return false;
    }/*from   ww w . j a v a 2  s  .  c o  m*/
    return context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
            .size() > 0;
}

From source file:Main.java

/**
 * @param context/* w w w .ja  va2  s .com*/
 *            used to check the device version and DownloadManager
 *            information
 * @return true if the download manager is available
 */
public static boolean isDownloadManagerAvailable(Context context) {
    try {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
            return false;
        }
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setClassName("com.android.providers.downloads.ui",
                "com.android.providers.downloads.ui.DownloadList");
        List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        return list.size() > 0;
    } catch (Exception e) {
        return false;
    }
}

From source file:Main.java

/**
 * Checks if there is any Pay by Bank app enabled CFI App installed on the device.
 *
 * @param context The context to use.//from   www. j  a va  2  s . c  om
 * @return True if there is at least one PBBA enabled CFI App available, false otherwise.
 * @see #openBankingApp(Context, String)
 */
public static boolean isCFIAppAvailable(@NonNull final Context context) {

    //noinspection ConstantConditions
    if (context == null) {
        throw new IllegalArgumentException("context == null");
    }

    final Intent zappIntent = new Intent();
    zappIntent.setData(new Uri.Builder().scheme(ZAPP_SCHEME).build());
    zappIntent.setAction(Intent.ACTION_VIEW);
    final ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(zappIntent,
            PackageManager.MATCH_DEFAULT_ONLY);
    return resolveInfo != null;
}

From source file:Main.java

public static Boolean isActionAvailable(Activity activity, int action) {
    Log.d(TAG, "[AirImagePickerUtils] Entering isActionAvailable");
    if (action == CROP_ACTION) {
        return isCropAvailable(activity);
    }//from w w w.  ja v  a2s.  c o  m

    final PackageManager packageManager = activity.getPackageManager();
    List<ResolveInfo> list = packageManager.queryIntentActivities(getIntentForAction(action),
            PackageManager.MATCH_DEFAULT_ONLY);

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

    return list.size() > 0;
}

From source file:Main.java

/**
 * Retrieve launcher activity name of the application from the context
 *
 * @param context The context of the application package.
 * @return launcher activity name of this application. From the
 *         "android:name" attribute./*from  w  w  w.ja  v a 2s . c o  m*/
 */
private static String getLauncherClassName(Context context) {
    PackageManager packageManager = context.getPackageManager();

    Intent intent = new Intent(Intent.ACTION_MAIN);
    // To limit the components this Intent will resolve to, by setting an
    // explicit package name.
    intent.setPackage(context.getPackageName());
    intent.addCategory(Intent.CATEGORY_LAUNCHER);

    // All Application must have 1 Activity at least.
    // Launcher activity must be found!
    ResolveInfo info = packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);

    // get a ResolveInfo containing ACTION_MAIN, CATEGORY_LAUNCHER
    // if there is no Activity which has filtered by CATEGORY_DEFAULT
    if (info == null) {
        info = packageManager.resolveActivity(intent, 0);
    }

    return info.activityInfo.name;
}

From source file:Main.java

/*******************
 * PRIVATE METHODS */*from w w  w  .  java2  s .  c o m*/
 *******************/

private static boolean urlCanBeHandled(Context aContext, String aURLString) {
    PackageManager packageManager = aContext.getPackageManager();
    Intent openAppIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(aURLString));
    List activitiesCanHandle = packageManager.queryIntentActivities(openAppIntent,
            PackageManager.MATCH_DEFAULT_ONLY);
    return activitiesCanHandle.size() != 0;
}

From source file:Main.java

/**
 * Returns a copy of {@param intent} with a class name set, if a class inside this app
 * has a corresponding intent filter.//from  w ww. java 2 s. c om
 */
private static Intent getIntentInAppIfExists(Context context, Intent intent) {
    try {
        final Intent intentCopy = new Intent(intent);
        // Force this intentCopy to open inside the current app.
        intentCopy.setPackage(context.getPackageName());
        final List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intentCopy,
                PackageManager.MATCH_DEFAULT_ONLY);
        if (list != null && list.size() != 0) {
            // Now that we know the intentCopy will work inside the current app, we
            // can return this intent non-null.
            if (list.get(0).activityInfo != null && !TextUtils.isEmpty(list.get(0).activityInfo.name)) {
                // Now that we know the class name, we may as well attach it to intentCopy
                // to prevent the package manager from needing to find it again inside
                // startActivity(). This is only needed for efficiency.
                intentCopy.setClassName(context.getPackageName(), list.get(0).activityInfo.name);
            }
            return intentCopy;
        }
        return null;
    } catch (Exception e) {
        // Don't let the package manager crash our app. If the package manager can't resolve the
        // intent here, then we can still call startActivity without calling setClass() first.
        return null;
    }
}