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:it.gulch.linuxday.android.fragments.MapFragment.java
private void launchDirections() { // Build intent to start Google Maps directions String uri = String.format(Locale.US, "http://maps.google.com/maps?f=d&daddr=%1$f,%2$f(%3$s)&dirflg=r", DESTINATION_LATITUDE, DESTINATION_LONGITUDE, DESTINATION_NAME); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); // If Google Maps app is found, don't allow to choose other apps to handle this intent List<ResolveInfo> resolveInfos = getActivity().getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (resolveInfos != null) { for (ResolveInfo info : resolveInfos) { if (GOOGLE_MAPS_PACKAGE_NAME.equals(info.activityInfo.packageName)) { intent.setPackage(GOOGLE_MAPS_PACKAGE_NAME); break; }// w w w . jav a 2 s . co m } } startActivity(intent); }
From source file:com.commonsware.android.camcon.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState == null) { output = new File(new File(getFilesDir(), PHOTOS), FILENAME); if (output.exists()) { output.delete();//ww w . j a v a 2 s. c o m } else { output.getParentFile().mkdirs(); } Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Uri outputUri = FileProvider.getUriForFile(this, AUTHORITY, output); i.putExtra(MediaStore.EXTRA_OUTPUT, outputUri); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { ClipData clip = ClipData.newUri(getContentResolver(), "A photo", outputUri); i.setClipData(clip); i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } else { List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; grantUriPermission(packageName, outputUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } } try { startActivityForResult(i, CONTENT_REQUEST); } catch (ActivityNotFoundException e) { Toast.makeText(this, R.string.msg_no_camera, Toast.LENGTH_LONG).show(); finish(); } } else { output = (File) savedInstanceState.getSerializable(EXTRA_FILENAME); } }
From source file:com.commonsware.android.camcon.CameraContentDemoActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (savedInstanceState == null) { output = new File(new File(getFilesDir(), PHOTOS), FILENAME); if (output.exists()) { output.delete();/*from w ww. j a v a 2 s . c om*/ } else { output.getParentFile().mkdirs(); } } else { output = (File) savedInstanceState.getSerializable(EXTRA_FILENAME); } outputUri = FileProvider.getUriForFile(this, AUTHORITY, output); if (savedInstanceState == null) { i.putExtra(MediaStore.EXTRA_OUTPUT, outputUri); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { ClipData clip = ClipData.newUri(getContentResolver(), "A photo", outputUri); i.setClipData(clip); i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } else { List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; grantUriPermission(packageName, outputUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } } startActivityForResult(i, CONTENT_REQUEST); } }
From source file:uk.co.richyhbm.coinbag.activities.AboutActivity.java
@Override public void onClick(View v) { if (v.getId() == R.id.bitcoin_donate || v.getId() == R.id.ethereum_donate) { DonationType donationType = DonationType.BITCOIN; if (v.getId() == R.id.bitcoin_donate) donationType = DonationType.BITCOIN; else if (v.getId() == R.id.ethereum_donate) donationType = DonationType.ETHEREUM; Intent donateIntent = new Intent("android.intent.action.VIEW", Uri.parse(donationType.getDonationUrl())); if (this.getPackageManager().queryIntentActivities(donateIntent, PackageManager.MATCH_DEFAULT_ONLY) .size() > 0) {//from www . jav a 2 s.c o m startActivity(donateIntent); } else { Intent intent = new Intent(this, DonateActivity.class); intent.putExtra(DonateActivity.DONATION_TYPE_INTENT_EXTRA, donationType.getValue()); startActivity(intent); } } }
From source file:jahirfiquitiva.iconshowcase.utilities.utils.Utils.java
public static String getDefaultLauncherPackage(@NonNull Context context) { final Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME); final ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); return resolveInfo.activityInfo.packageName; }
From source file:com.fuck_boilerplate.rx_paparazzo.interactors.TakePhoto.java
/** * Workaround for Android bug.<br/> * See https://code.google.com/p/android/issues/detail?id=76683 <br/> * See http://stackoverflow.com/questions/18249007/how-to-use-support-fileprovider-for-sharing-content-to-other-apps * @param intent/* w w w . java 2 s . c o m*/ * @param uri */ private void grantFileReadWritePermissions(Intent intent, Uri uri) { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { List<ResolveInfo> resInfoList = targetUi.getContext().getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; targetUi.getContext().grantUriPermission(packageName, uri, READ_WRITE_PERMISSIONS); } } }
From source file:com.cerema.cloud2.ui.dialog.ShareLinkToDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { mIntent = getArguments().getParcelable(ARG_INTENT); String[] packagesToExclude = getArguments().getStringArray(ARG_PACKAGES_TO_EXCLUDE); List<String> packagesToExcludeList = Arrays .asList(packagesToExclude != null ? packagesToExclude : new String[0]); PackageManager pm = getActivity().getPackageManager(); List<ResolveInfo> activities = pm.queryIntentActivities(mIntent, PackageManager.MATCH_DEFAULT_ONLY); Iterator<ResolveInfo> it = activities.iterator(); ResolveInfo resolveInfo;//from w w w. j a va 2 s . co m while (it.hasNext()) { resolveInfo = it.next(); if (packagesToExcludeList.contains(resolveInfo.activityInfo.packageName.toLowerCase())) { it.remove(); } } boolean sendAction = mIntent.getBooleanExtra(Intent.ACTION_SEND, false); if (!sendAction) { // add activity for copy to clipboard Intent copyToClipboardIntent = new Intent(getActivity(), CopyToClipboardActivity.class); List<ResolveInfo> copyToClipboard = pm.queryIntentActivities(copyToClipboardIntent, 0); if (!copyToClipboard.isEmpty()) { activities.add(copyToClipboard.get(0)); } } Collections.sort(activities, new ResolveInfo.DisplayNameComparator(pm)); mAdapter = new ActivityAdapter(getActivity(), pm, activities); return createSelector(sendAction); }
From source file:com.adguard.android.commons.BrowserUtils.java
public static void openSamsungBlockingOptions(Context context) { Intent intent = new Intent(); intent.setAction(SAMSUNG_CONTENT_BLOCKER_ACTION); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (list.size() > 0) { boolean found = false; for (ResolveInfo info : list) { if (info.activityInfo.packageName.contains(SAMSUNG_PACKAGE_PREFIX) || info.activityInfo.packageName.contains(SAMSUNG)) { found = true;//from ww w. j av a2 s. c om intent.setClassName(info.activityInfo.packageName, info.activityInfo.name); } } if (found) { context.startActivity(intent); } } }
From source file:com.xbm.android.matisse.internal.utils.MediaStoreCompat.java
public void dispatchCaptureIntent(Context context, int requestCode) { Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (captureIntent.resolveActivity(context.getPackageManager()) != null) { File photoFile = null;//from w ww . j a v a2 s. co m try { photoFile = createImageFile(); } catch (IOException e) { e.printStackTrace(); } if (photoFile != null) { mCurrentPhotoPath = photoFile.getAbsolutePath(); mCurrentPhotoUri = FileProvider.getUriForFile(mContext.get(), mCaptureStrategy.authority, photoFile); captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCurrentPhotoUri); captureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(captureIntent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; context.grantUriPermission(packageName, mCurrentPhotoUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); } } if (mFragment != null) { mFragment.get().startActivityForResult(captureIntent, requestCode); } else { mContext.get().startActivityForResult(captureIntent, requestCode); } } } }
From source file:com.android.browser.DownloadHandler.java
/** * Notify the host application a download should be done, or that * the data should be streamed if a streaming viewer is available. * @param activity Activity requesting the download. * @param url The full url to the content that should be downloaded * @param userAgent User agent of the downloading application. * @param contentDisposition Content-disposition http header, if present. * @param mimetype The mimetype of the content reported by the server * @param referer The referer associated with the downloaded url * @param privateBrowsing If the request is coming from a private browsing tab. *//*ww w . j a va 2s . co m*/ public static void onDownloadStart(Activity activity, String url, String userAgent, String contentDisposition, String mimetype, String referer, boolean privateBrowsing) { // if we're dealing wih A/V content that's not explicitly marked // for download, check if it's streamable. if (contentDisposition == null || !contentDisposition.regionMatches(true, 0, "attachment", 0, 10)) { // query the package manager to see if there's a registered handler // that matches. Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse(url), mimetype); ResolveInfo info = activity.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); if (info != null) { ComponentName myName = activity.getComponentName(); // If we resolved to ourselves, we don't want to attempt to // load the url only to try and download it again. if (!myName.getPackageName().equals(info.activityInfo.packageName) || !myName.getClassName().equals(info.activityInfo.name)) { // someone (other than us) knows how to handle this mime // type with this scheme, don't download. try { activity.startActivity(intent); return; } catch (ActivityNotFoundException ex) { if (LOGD_ENABLED) { Log.d(LOGTAG, "activity not found for " + mimetype + " over " + Uri.parse(url).getScheme(), ex); } // Best behavior is to fall back to a download in this // case } } } } onDownloadStartNoStream(activity, url, userAgent, contentDisposition, mimetype, referer, privateBrowsing); }