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: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 an intent with the specified action. If no suitable package is * found, this method returns false./*from www . j ava 2 s .co m*/ * * @param context * The application's environment. * @param action * The Intent action 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(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 isCropAvailable(Activity activity) { Log.d(TAG, "[AirImagePickerUtils] isCropAvailable"); final PackageManager packageManager = activity.getPackageManager(); Intent intent = getIntentForAction(CROP_ACTION); intent.setType("image/*"); List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); Log.d(TAG, "[AirImagePickerUtils] Exiting isCropAvailable"); return list.size() > 0; }
From source file:com.codeslap.topy.BaseMultiPaneActivity.java
/** {@inheritDoc} */ @Override/*from w w w.jav a 2s. c o m*/ public void openActivityOrFragment(final Intent intent) { final PackageManager pm = getPackageManager(); List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resolveInfoList) { final FragmentReplaceInfo fri = onSubstituteFragmentForActivityLaunch(resolveInfo.activityInfo.name); if (fri != null) { final Bundle arguments = intentToFragmentArguments(intent); final FragmentManager fm = getSupportFragmentManager(); try { Fragment fragment = (Fragment) fri.getFragmentClass().newInstance(); fragment.setArguments(arguments); FragmentTransaction ft = fm.beginTransaction(); ft.replace(fri.getContainerId(), fragment, fri.getFragmentTag()); onBeforeCommitReplaceFragment(fm, ft, fragment); ft.commit(); } catch (InstantiationException e) { throw new IllegalStateException("Error creating new fragment.", e); } catch (IllegalAccessException e) { throw new IllegalStateException("Error creating new fragment.", e); } return; } } super.openActivityOrFragment(intent); }
From source file:ca.rmen.android.scrumchatter.export.Export.java
/** * Bring up the chooser to send the file. *//*from ww w .j av a 2 s .c om*/ static void share(Context context, File file, String mimeType) { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.export_message_subject)); sendIntent.putExtra(Intent.EXTRA_TEXT, context.getString(R.string.export_message_body)); Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileprovider", file); sendIntent.putExtra(Intent.EXTRA_STREAM, uri); sendIntent.setType(mimeType); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(sendIntent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; context.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION); Log.v(TAG, "grant permission to " + packageName); } } context.startActivity( Intent.createChooser(sendIntent, context.getResources().getText(R.string.action_share))); }
From source file:com.trigger_context.conf.Action_Post_Tweet.java
public Intent findTwitterClient() { final String[] twitterApps = { "com.twitter.android", // official - 10 // 000 "com.twidroid", // twidroid - 5 000 "com.handmark.tweetcaster", // Tweetcaster - 5 000 "com.thedeck.android" }; // TweetDeck - 5 000 ; Intent tweetIntent = new Intent(); tweetIntent.setType("text/plain"); final PackageManager packageManager = getPackageManager(); List<ResolveInfo> list = packageManager.queryIntentActivities(tweetIntent, PackageManager.MATCH_DEFAULT_ONLY); for (String twitterApp : twitterApps) { for (ResolveInfo resolveInfo : list) { String p = resolveInfo.activityInfo.packageName; if (p != null && p.startsWith(twitterApp)) { tweetIntent.setPackage(p); return tweetIntent; }// www .j a va2 s . co m } } return null; }
From source file:com.adguard.android.commons.BrowserUtils.java
public static Set<String> getBrowsersAvailableByIntent(Context context) { Set<String> result = new HashSet<>(); Intent intent = new Intent(); intent.setAction(SAMSUNG_CONTENT_BLOCKER_ACTION); List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (list.size() > 0) { for (ResolveInfo info : list) { if (info.activityInfo.packageName.contains(YANDEX)) { result.add(YANDEX);/*from ww w .j ava2 s . co m*/ } else if (info.activityInfo.packageName.contains(SAMSUNG_PACKAGE_PREFIX) || info.activityInfo.packageName.contains(SAMSUNG)) { result.add(SAMSUNG); } } } return result; }
From source file:org.onebusaway.android.map.googlemapsv2.ProprietaryMapHelpV2.java
/** * Prompts the user to install Android Maps V2 from Google Play *//*w ww . j av a 2 s.c o m*/ public static void promptUserInstallMaps(final Context context) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setMessage(context.getString(R.string.please_install_google_maps_dialog_title)); builder.setCancelable(false); builder.setPositiveButton(context.getString(R.string.install_google_maps_positive_button), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(context.getString(R.string.android_maps_v2_market_url))); ResolveInfo info = context.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); if (info != null) { context.startActivity(intent); } else { // User doesn't have Play Store installed AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setMessage(context.getString(R.string.no_play_store)); builder.setCancelable(true); builder.setPositiveButton(context.getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); AlertDialog d = builder.create(); d.show(); } } }); AlertDialog dialog = builder.create(); dialog.show(); }
From source file:com.app.common.util.IntentUtils.java
public static void startEmailActivity(Context context, String to, String subject, String body) { final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("message/rfc822"); if (!TextUtils.isEmpty(to)) { intent.putExtra(Intent.EXTRA_EMAIL, new String[] { to }); }/*from w ww .ja v a2 s .c o m*/ if (!TextUtils.isEmpty(subject)) { intent.putExtra(Intent.EXTRA_SUBJECT, subject); } if (!TextUtils.isEmpty(body)) { intent.putExtra(Intent.EXTRA_TEXT, body); } final PackageManager pm = (PackageManager) context.getPackageManager(); try { if (pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() == 0) { intent.setType("text/plain"); } } catch (Exception e) { Log.w("Exception encountered while looking for email intent receiver.", e); } context.startActivity(intent); }
From source file:Main.java
/** * Method to check if implicit intent to open entry for app "OI Notepad" in appstore client on current * device can be handled.// w w w.j a v a 2 s . com * If you try to dispatch the request to open an entry in the appstore client when no appstore client * is installed on the device, then the app will immediately crash. * * @param context Context (e.g. self-reference of calling activity) needed for accessing package manager. * * @return <tt>True</tt> if intent to open appstore entry for "OI Notepad" can be handled, <tt>false</tt> * otherwise. */ public static boolean isIntentToOpenAppStoreClientSupported(Context context) { final int flags = PackageManager.MATCH_DEFAULT_ONLY; PackageManager packageManager = context.getPackageManager(); Intent intent = createIntentForOINotepadAppstoreEntry(); List<ResolveInfo> list = packageManager.queryIntentActivities(intent, flags); // If at least one app was found that can handle the intent then this method returns "true" return list.size() > 0; }
From source file:com.commonsware.android.videorecord.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState == null) { output = new File(new File(getFilesDir(), VIDEOS), FILENAME); if (output.exists()) { output.delete();/*from w w w.j av a2 s . c o m*/ } else { output.getParentFile().mkdirs(); } } else { output = (File) savedInstanceState.getSerializable(EXTRA_FILENAME); } outputUri = FileProvider.getUriForFile(this, AUTHORITY, output); if (savedInstanceState == null) { Intent i = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); i.putExtra(MediaStore.EXTRA_OUTPUT, outputUri); i.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_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 | Intent.FLAG_GRANT_READ_URI_PERMISSION); } } startActivityForResult(i, REQUEST_ID); } }