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

/**
 * Returns true if the given intent can be handled on this device
 * @param context//from ww w . j  a  v a 2 s .  co  m
 * @param intent
 * @return
 */
public static boolean canHandleIntent(@NonNull Context context, Intent intent) {
    PackageManager packageManager = context.getPackageManager();
    List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    return resolveInfo.size() > 0;
}

From source file:Main.java

/**
 * Indicates whether the specified action can be used as an intent example: isIntentAvailable(this,
 * "com.google.zxing.client.android.SCAN");
 *
 * @param pContext/*from w ww.  ja v a2  s. com*/
 * @param pAction
 * @return
 */
private static boolean isIntentAvailable(Context pContext, String pAction) {
    final PackageManager packageManager = pContext.getPackageManager();
    final Intent intent = new Intent(pAction);
    List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

From source file:Main.java

private static boolean intentAvailable(Context context, Intent intent) {
    PackageManager packageManager = context.getPackageManager();
    List list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

From source file:Main.java

/**
 * Returns true if the intent action is available on the device, false
 * otherwise.//from   www . ja v  a2s  .c o  m
 */
public static boolean isIntentAvailable(Context ctx, String action) {
    PackageManager pm = ctx.getPackageManager();
    Intent intent = new Intent(action);
    return pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
}

From source file:Main.java

/**
 * This method queries the system to check if there is a viewer available or not. If no suitable viewer is
 * found, this method returns false./* w w  w . ja v  a  2  s .c o m*/
 * @return True if PDF viewer is available, false otherwise.
 */
public static boolean isViewerAvailable(Context context, Uri uri) {
    final PackageManager packageManager = context.getPackageManager();
    final Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(uri);
    final List<ResolveInfo> list = packageManager.queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

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) {

            }// w w w.ja  v  a  2  s . c  om
            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:Main.java

/**
 * Check if action available installed//from w  w  w . j a  v a 2  s  .  co  m
 *
 * @param context Context of current app
 * @param action Package of application to check
 * @return true if passed package installed
 */
public static boolean isIntentAvailable(Context context, String action) {
    final PackageManager packageManager = context.getPackageManager();
    final Intent intent = new Intent(action);
    assert packageManager != null;
    List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

From source file:Main.java

/**
 * Checks if there is any of the CFI apps installed on the device supports PBBA payment.
 *
 * @param context application context//from w  w  w  . j av  a  2 s.c  om
 * @return true if available
 */
public static boolean isZappCFIAppAvailable(@NonNull final Context context) {
    final Intent zappIntent = new Intent();
    zappIntent.setAction(Intent.ACTION_VIEW);
    zappIntent.setData(new Uri.Builder().scheme(ZAPP_SCHEME).build());
    final ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(zappIntent,
            PackageManager.MATCH_DEFAULT_ONLY);
    return resolveInfo != null;
}

From source file:Main.java

/**
 * Indicates whether the specified action can be used as an intent. This
 * method queries the package manager for installed packages that can
 * respond to the specified intent. If no suitable package is
 * found, this method returns false./*from  w  w  w .j a va  2s.c o  m*/
 *
 * @param context The application's environment.
 * @param intent The Intent to check for availability.
 *
 * @return True if an Intent with the specified action can be sent and
 *         responded to, false otherwise.
 */
public static boolean isIntentAvailable(final Context context, final Intent intent) {
    final PackageManager packageManager = context.getPackageManager();

    List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

From source file:Main.java

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