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:ca.mymenuapp.ui.activities.RestaurantActivity.java

/**
 * Check if any apps are installed on the app to receive this intent.
 */// w w  w  .j  ava2  s. c  om
public static boolean isAvailable(Context ctx, Intent intent) {
    final PackageManager mgr = ctx.getPackageManager();
    List<ResolveInfo> list = mgr.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

From source file:com.limemobile.app.plugin.PluginClientFragmentActivity.java

@Override
public boolean stopService(Intent service) {
    if (mProxyActivity == null) {
        return super.stopService(service);
    }/*from  ww w. j ava 2  s. c  o m*/
    List<ResolveInfo> resolveInfos = mContext.getPackageManager().queryIntentServices(service,
            PackageManager.MATCH_DEFAULT_ONLY);
    if (resolveInfos != null && !resolveInfos.isEmpty()) {
        return super.stopService(service);
    } else {
        service.setPackage(mPluginPackage.mPackageName);
        return PluginClientManager.sharedInstance(mContext).stopService(mContext, service);
    }
}

From source file:com.linkbubble.util.Util.java

static public ResolveInfo getDefaultBrowser(PackageManager packageManager) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(Config.SET_DEFAULT_BROWSER_URL));
    return packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
}

From source file:com.e2g.ecocicle.barcode.IntentIntegrator.java

private String findTargetAppPackage(Intent intent) {
    PackageManager pm = activity.getPackageManager();
    List<ResolveInfo> availableApps = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    if (availableApps != null) {
        for (String targetApp : targetApplications) {
            if (contains(availableApps, targetApp)) {
                return targetApp;
            }//ww  w .  jav  a  2  s. com
        }
    }
    return null;
}

From source file:com.filemanager.free.utils.Futils.java

private boolean isSelfDefault(File f, Context c) {
    Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(f), MimeTypes.getMimeType(f));
    String s = "";
    ResolveInfo rii = c.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
    if (rii != null && rii.activityInfo != null)
        s = rii.activityInfo.packageName;
    if (s.equals("com.filemanager.free") || rii == null)
        return true;
    else/*from ww  w.  ja v  a  2  s.  c  om*/
        return false;
}

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();//w  ww .j  a v  a2s . c om
    return result;
}

From source file:com.brq.wallet.activity.export.BackupToPdfActivity.java

private void grantPermissions(Intent intent, Uri uri) {
    // grant permissions for all apps that can handle given intent
    // if we know of any malicious app that tries to intercept this,
    // we could block it here based on packageName
    PackageManager packageManager = Preconditions.checkNotNull(getPackageManager());
    List<ResolveInfo> resInfoList = packageManager.queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    for (ResolveInfo resolveInfo : resInfoList) {
        String packageName = resolveInfo.activityInfo.packageName;
        grantUriPermission(packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
    }// w  w  w . java  2s.  c  o m
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * This function allows to know if there is an application that responds to
 * the specified action.//  w ww  .jav a2  s.  c om
 * 
 * @param context
 * @param action   Action that requires an application.
 * @return
 */
public static boolean system_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:edu.cmu.cylab.starslinger.view.ComposeFragment.java

@SuppressWarnings("deprecation")
private void drawFileImage() {
    String filenameArray[] = mFilePath.split("\\.");
    String extension = filenameArray[filenameArray.length - 1];
    String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);

    if (mThumb != null && mThumb.length > 0) {
        ByteArrayInputStream in = new ByteArrayInputStream(mThumb);
        BitmapDrawable tn = new BitmapDrawable(in);
        mImageViewFile.setImageDrawable(tn);
    } else {/*ww  w .  j a v a2s  .  c o  m*/
        Intent viewIntent = new Intent(Intent.ACTION_VIEW);
        viewIntent.setType(mime);
        PackageManager pm = getActivity().getPackageManager();
        List<ResolveInfo> lract = pm.queryIntentActivities(viewIntent, PackageManager.MATCH_DEFAULT_ONLY);

        boolean resolved = false;

        for (ResolveInfo ri : lract) {
            if (!resolved) {
                try {
                    Drawable icon = pm.getApplicationIcon(ri.activityInfo.packageName);
                    mImageViewFile.setImageDrawable(icon);
                    resolved = true;
                } catch (NameNotFoundException e) {
                    mImageViewFile.setImageDrawable(getResources().getDrawable(R.drawable.ic_menu_file));
                }
            }
        }

    }
}

From source file:org.fs.galleon.presenters.ToolsFragmentPresenter.java

private void dispatchTakePictureIntent() {
    createIfNotExists().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
            .subscribe(file -> {/*from  www  .  ja  v  a  2 s  . com*/
                if (file.exists()) {
                    log(Log.INFO, String.format(Locale.ENGLISH, "%s is temp file.", file.getAbsolutePath()));
                }
                if (view.isAvailable()) {
                    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    if (intent.resolveActivity(view.getContext().getPackageManager()) != null) {
                        this.tempTakenPhoto = file;//set it in property
                        Uri uri = FileProvider.getUriForFile(view.getContext(), GRANT_PERMISSION, file);
                        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
                        //fileProvider requires gran permission to others access that uri
                        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
                            final Context context = view.getContext();
                            List<ResolveInfo> infos = context.getPackageManager().queryIntentActivities(intent,
                                    PackageManager.MATCH_DEFAULT_ONLY);
                            if (infos != null) {
                                StreamSupport.stream(infos).filter(x -> x.activityInfo != null)
                                        .map(x -> x.activityInfo.packageName).forEach(pack -> {
                                            context.grantUriPermission(pack, uri,
                                                    Intent.FLAG_GRANT_WRITE_URI_PERMISSION
                                                            | Intent.FLAG_GRANT_READ_URI_PERMISSION);
                                        });
                            }
                        }
                        view.startActivityForResult(intent, REQUEST_TAKE_PHOTO);
                    } else {
                        view.showError("You need to install app that can capture photo.");
                    }
                }
            }, this::log);
}