List of usage examples for android.content.pm PackageManager MATCH_DEFAULT_ONLY
int MATCH_DEFAULT_ONLY
To view the source code for android.content.pm PackageManager MATCH_DEFAULT_ONLY.
Click Source Link
From source file:android.support.v7.widget.SearchView.java
@TargetApi(Build.VERSION_CODES.FROYO) private boolean hasVoiceSearch() { if (mSearchable != null && mSearchable.getVoiceSearchEnabled()) { Intent testIntent = null;//from w w w . java2 s . c om if (mSearchable.getVoiceSearchLaunchWebSearch()) { testIntent = mVoiceWebSearchIntent; } else if (mSearchable.getVoiceSearchLaunchRecognizer()) { testIntent = mVoiceAppSearchIntent; } if (testIntent != null) { ResolveInfo ri = getContext().getPackageManager().resolveActivity(testIntent, PackageManager.MATCH_DEFAULT_ONLY); return ri != null; } } return false; }
From source file:net.gsantner.opoc.util.ShareUtil.java
/** * Request edit of image (by image editor/viewer - for example to crop image) * * @param file File that should be edited *//*from w w w .ja va2s. co m*/ public void requestPictureEdit(File file) { Uri uri = getUriByFileProviderAuthority(file); int flags = Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION; Intent intent = new Intent(Intent.ACTION_EDIT); intent.setDataAndType(uri, "image/*"); intent.addFlags(flags); intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); intent.putExtra(EXTRA_FILEPATH, file.getAbsolutePath()); for (ResolveInfo resolveInfo : _context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)) { String packageName = resolveInfo.activityInfo.packageName; _context.grantUriPermission(packageName, uri, flags); } _context.startActivity(Intent.createChooser(intent, null)); }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
public static boolean application_isCallable(Activity activity, Intent intent) { List<ResolveInfo> list = activity.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return list.size() > 0; }
From source file:com.vuze.android.remote.fragment.FilesFragment.java
@SuppressWarnings("unused") protected boolean reallyStreamFile(Map<?, ?> selectedFile) { final String contentURL = getContentURL(selectedFile); if (contentURL != null && contentURL.length() > 0) { Uri uri = Uri.parse(contentURL); Intent intent = new Intent(Intent.ACTION_VIEW, uri); String name = MapUtils.getMapString(selectedFile, "name", "video"); intent.putExtra("title", name); String extension = MimeTypeMap.getFileExtensionFromUrl(contentURL).toLowerCase(Locale.US); String mimetype = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); if (mimetype != null && tryLaunchWithMimeFirst) { intent.setType(mimetype);/* w w w . ja v a 2 s . c om*/ } Class<?> fallBackIntentClass = VideoViewer.class; if (mimetype != null && mimetype.startsWith("image")) { fallBackIntentClass = ImageViewer.class; } final PackageManager packageManager = getActivity().getPackageManager(); List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (AndroidUtils.DEBUG) { Log.d(TAG, "num intents " + list.size()); for (ResolveInfo info : list) { ComponentInfo componentInfo = AndroidUtils.getComponentInfo(info); Log.d(TAG, info.toString() + "/" + (componentInfo == null ? "null" : (componentInfo.name + "/" + componentInfo))); } } if (list.size() == 0) { // Intent will launch, but show message to the user: // "Opening web browser links is not supported" intent.setClass(getActivity(), fallBackIntentClass); } if (list.size() == 1) { ResolveInfo info = list.get(0); ComponentInfo componentInfo = AndroidUtils.getComponentInfo(info); if (componentInfo != null && componentInfo.name != null) { if ("com.amazon.unifiedshare.actionchooser.BuellerShareActivity".equals(componentInfo.name) || componentInfo.name.startsWith("com.google.android.tv.frameworkpackagestubs.Stubs")) { intent.setClass(getActivity(), fallBackIntentClass); } } } try { startActivity(intent); if (AndroidUtils.DEBUG) { Log.d(TAG, "Started " + uri + " MIME: " + intent.getType()); } } catch (java.lang.SecurityException es) { if (AndroidUtils.DEBUG) { Log.d(TAG, "ERROR launching. " + es.toString()); } if (mimetype != null) { try { Intent intent2 = new Intent(Intent.ACTION_VIEW, uri); intent2.putExtra("title", name); if (!tryLaunchWithMimeFirst) { intent2.setType(mimetype); } list = packageManager.queryIntentActivities(intent2, PackageManager.MATCH_DEFAULT_ONLY); if (AndroidUtils.DEBUG) { Log.d(TAG, "num intents " + list.size()); for (ResolveInfo info : list) { ComponentInfo componentInfo = AndroidUtils.getComponentInfo(info); Log.d(TAG, info.toString() + "/" + (componentInfo == null ? "null" : (componentInfo.name + "/" + componentInfo))); } } startActivity(intent2); if (AndroidUtils.DEBUG) { Log.d(TAG, "Started with" + (intent2.getType() == null ? " no" : " ") + " mime: " + uri); } return true; } catch (Throwable ex2) { if (AndroidUtils.DEBUG) { Log.d(TAG, "no intent for view. " + ex2.toString()); } } } Toast.makeText(getActivity().getApplicationContext(), getActivity().getResources().getString(R.string.intent_security_fail), Toast.LENGTH_LONG) .show(); } catch (android.content.ActivityNotFoundException ex) { if (AndroidUtils.DEBUG) { Log.d(TAG, "no intent for view. " + ex.toString()); } if (mimetype != null) { try { Intent intent2 = new Intent(Intent.ACTION_VIEW, uri); intent2.putExtra("title", name); if (!tryLaunchWithMimeFirst) { intent2.setType(mimetype); } startActivity(intent2); if (AndroidUtils.DEBUG) { Log.d(TAG, "Started (no mime set) " + uri); } return true; } catch (android.content.ActivityNotFoundException ex2) { if (AndroidUtils.DEBUG) { Log.d(TAG, "no intent for view. " + ex2.toString()); } } } Toast.makeText(getActivity().getApplicationContext(), getActivity().getResources().getString(R.string.no_intent), Toast.LENGTH_SHORT).show(); } return true; } return true; }
From source file:org.kontalk.ui.AbstractComposeFragment.java
/** Starts an activity for shooting a picture. */ void selectPhotoAttachment() { try {// w w w .j av a2 s.c om // check if camera is available final PackageManager packageManager = getActivity().getPackageManager(); final Intent intent = SystemUtils.externalIntent(MediaStore.ACTION_IMAGE_CAPTURE); List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (list.size() <= 0) throw new UnsupportedOperationException(); mCurrentPhoto = MediaStorage.getOutgoingPhotoFile(); Uri uri = Uri.fromFile(mCurrentPhoto); Intent take = SystemUtils.externalIntent(MediaStore.ACTION_IMAGE_CAPTURE); take.putExtra(MediaStore.EXTRA_OUTPUT, uri); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { take.setClipData(ClipData.newUri(getContext().getContentResolver(), "Picture path", uri)); } startActivityForResult(take, SELECT_ATTACHMENT_PHOTO); } catch (UnsupportedOperationException ue) { Toast.makeText(getActivity(), R.string.chooser_error_no_camera_app, Toast.LENGTH_LONG).show(); } catch (IOException e) { Log.e(TAG, "error creating temp file", e); Toast.makeText(getActivity(), R.string.chooser_error_no_camera, Toast.LENGTH_LONG).show(); } }
From source file:com.hichinaschool.flashcards.libanki.Utils.java
public static boolean isIntentAvailable(Context context, String action, ComponentName componentName) { final PackageManager packageManager = context.getPackageManager(); final Intent intent = new Intent(action); intent.setComponent(componentName);//from 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.onesignal.OneSignal.java
private static void fireIntentFromNotificationOpen(Context inContext, JSONArray data) { PackageManager packageManager = inContext.getPackageManager(); boolean isCustom = false; Intent intent = new Intent().setAction("com.onesignal.NotificationOpened.RECEIVE") .setPackage(inContext.getPackageName()); List<ResolveInfo> resolveInfo = packageManager.queryBroadcastReceivers(intent, PackageManager.GET_INTENT_FILTERS); if (resolveInfo.size() > 0) { intent.putExtra("onesignal_data", data.toString()); inContext.sendBroadcast(intent); isCustom = true;//from w ww. j a v a 2 s. c o m } // Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. resolveInfo = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (resolveInfo.size() > 0) { if (!isCustom) intent.putExtra("onesignal_data", data.toString()); isCustom = true; intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); inContext.startActivity(intent); } if (!isCustom) { try { ApplicationInfo ai = inContext.getPackageManager().getApplicationInfo(inContext.getPackageName(), PackageManager.GET_META_DATA); Bundle bundle = ai.metaData; String defaultStr = bundle.getString("com.onesignal.NotificationOpened.DEFAULT"); isCustom = "DISABLE".equals(defaultStr); } catch (Throwable t) { Log(LOG_LEVEL.ERROR, "", t); } } if (!isCustom) { Intent launchIntent = inContext.getPackageManager() .getLaunchIntentForPackage(inContext.getPackageName()); if (launchIntent != null) { launchIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); inContext.startActivity(launchIntent); } } }
From source file:com.rks.musicx.misc.utils.Helper.java
/** * check activity/class/package present or not in the device * @param context/* w ww . j av a2 s. c om*/ * @param intent * @return */ public static boolean isActivityPresent(Context context, Intent intent) { List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return list.size() > 0; }
From source file:info.guardianproject.otr.app.im.app.NewChatActivity.java
private boolean isCallable(Intent intent) { List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return list.size() > 0; }
From source file:com.android.contacts.list.DefaultContactBrowseListFragment.java
private boolean hasExportIntentHandler() { final Intent intent = new Intent(); intent.setAction("com.android.providers.contacts.DUMP_DATABASE"); final List<ResolveInfo> receivers = getContext().getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return receivers != null && receivers.size() > 0; }