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
public static boolean isIntentAvailable(Context context, Intent intent, boolean defaultOnly) { List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent, defaultOnly ? PackageManager.MATCH_DEFAULT_ONLY : 0); return list.size() > 0; }
From source file:Main.java
public static boolean isIntentAvailable(final Context context, final String className) { final PackageManager packageManager = context.getPackageManager(); final Intent intent = new Intent(className); final List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return (list.size() > 0); }
From source file:Main.java
/** * Checks the availability of the DownloadManager. * * @param context used to update the device version and DownloadManager information * @return true if the download manager is available *///from w w w . ja v a 2s. c o m public static boolean isDownloadManagerAvailable(Context context) { try { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) { return false; } Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setClassName("com.android.providers.downloads.ui", "com.android.providers.downloads.ui.DownloadList"); List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return !list.isEmpty(); } catch (Exception e) { return false; } }
From source file:Main.java
public static Drawable getIconForIntent(final Context context, Intent i) { PackageManager pm = context.getPackageManager(); List<ResolveInfo> infos = pm.queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY); if (infos.size() > 0) { return infos.get(0).loadIcon(pm); }//from w ww.j ava 2 s . c o m return 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 an intent with the specified action. If no suitable package is * found, this method returns false.//from w w w.j a v a 2 s . c o 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(final Context context, final 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 isIntentAvailable(Context context, String action) { final PackageManager packageManager = context.getPackageManager(); final Intent intent = new Intent(action); List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return resolveInfo != null && !resolveInfo.isEmpty(); }
From source file:Main.java
/** * @param context used to check the device version and DownloadManager information * @return true if the download manager is available *///from w ww .ja v a 2 s.c o m //http://stackoverflow.com/questions/3028306/download-a-file-with-android-and-showing-the-progress-in-a-progressdialog public static boolean isDownloadManagerAvailable() { try { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) { return false; } Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setClassName("com.android.providers.downloads.ui", "com.android.providers.downloads.ui.DownloadList"); List<ResolveInfo> list = m_TempContext.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return list.size() > 0; } catch (Exception e) { return false; } }
From source file:Main.java
public static boolean canBeStarted(Context context, Intent intent, boolean checkSignature) { final PackageManager manager = context.getApplicationContext().getPackageManager(); final ResolveInfo info = manager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); if (info == null) { return false; }/*from w w w. ja va 2 s .c o m*/ final ActivityInfo activityInfo = info.activityInfo; if (activityInfo == null) { return false; } if (!checkSignature) { return true; } return PackageManager.SIGNATURE_MATCH == manager.checkSignatures(context.getPackageName(), activityInfo.packageName); }
From source file:Main.java
public static void shareOnTwitter(Context pContext, String urlToShare) { Intent tweetIntent = new Intent(Intent.ACTION_SEND); tweetIntent.putExtra(Intent.EXTRA_TEXT, urlToShare); tweetIntent.setType("text/plain"); PackageManager packManager = pContext.getPackageManager(); List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(tweetIntent, PackageManager.MATCH_DEFAULT_ONLY); boolean resolved = false; for (ResolveInfo resolveInfo : resolvedInfoList) { if (resolveInfo.activityInfo.packageName.startsWith("com.twitter.android")) { tweetIntent.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name); resolved = true;/*w ww . jav a2 s . c o m*/ break; } } if (resolved) { pContext.startActivity(tweetIntent); } else { Intent i = new Intent(); i.putExtra(Intent.EXTRA_TEXT, urlToShare); i.setAction(Intent.ACTION_VIEW); i.setData(Uri.parse("https://twitter.com/intent/tweet?text=message&via=profileName")); pContext.startActivity(i); } }
From source file:Main.java
static boolean isSystemApp(Context context, Intent intent) { PackageManager pm = context.getPackageManager(); ComponentName cn = intent.getComponent(); String packageName = null;//from ww w . j a v a2 s .co m if (cn == null) { ResolveInfo info = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); if ((info != null) && (info.activityInfo != null)) { packageName = info.activityInfo.packageName; } } else { packageName = cn.getPackageName(); } if (packageName != null) { try { PackageInfo info = pm.getPackageInfo(packageName, 0); return (info != null) && (info.applicationInfo != null) && ((info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0); } catch (NameNotFoundException e) { return false; } } else { return false; } }