List of usage examples for android.content.pm PackageManager queryIntentActivities
public abstract List<ResolveInfo> queryIntentActivities(Intent intent, @ResolveInfoFlags int flags);
From source file:Main.java
/** * This method check if an <tt>uri</tt> can be opened by android system. * @param uri the intent uri/*from w w w . ja va 2 s. c o m*/ * @param context current context * @return <tt>true</tt> if <tt>uri</tt> can be opened by android system. */ public static boolean canOpenUri(Uri uri, Context context) { Intent intent = new Intent(Intent.ACTION_VIEW, uri); PackageManager packageManager = context.getPackageManager(); List<ResolveInfo> resolvedActivities = packageManager.queryIntentActivities(intent, 0); if (resolvedActivities.size() > 0) { return true; } return false; }
From source file:Main.java
private static void shareImageOnFacebook(String imagePath, Context context) { Log.d("CitationsManager-ShareOnFb", "sharing the image " + imagePath); Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); shareIntent.setType("image/*"); // shareIntent.putExtra(Intent.EXTRA_TEXT, "www.google.com"); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(imagePath))); PackageManager pm = context.getPackageManager(); List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0); for (final ResolveInfo app : activityList) { Log.d("CitationsManager-ShareOnFb", app.activityInfo.name); if ((app.activityInfo.name).contains("com.facebook") && !(app.activityInfo.name).contains("messenger") && !(app.activityInfo.name).contains("pages")) { final ActivityInfo activity = app.activityInfo; final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name); shareIntent.addCategory(Intent.CATEGORY_LAUNCHER); shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP); shareIntent.setComponent(name); context.startActivity(shareIntent); break; }/*from w w w .j a va2 s.c o m*/ } }
From source file:Main.java
public static List<Intent> createTakePictureIntentList(@NonNull Context context, @NonNull Uri outputFileUri) { List<Intent> cameraIntents = new ArrayList<>(); Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); PackageManager packageManager = context.getPackageManager(); List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0); for (ResolveInfo res : listCam) { String packageName = res.activityInfo.packageName; Intent intent = new Intent(captureIntent); intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); intent.setPackage(packageName);/*from ww w. j a va 2s . c om*/ intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); cameraIntents.add(intent); } return cameraIntents; }
From source file:Main.java
/** Checks if the device can send SMS messages. * * @param context Context for obtaining the package manager. * @return true if you can send SMS, false otherwise. *//*from ww w . ja v a 2s. c o m*/ public static boolean canSendSms(Context context) { Uri smsUri = Uri.parse("smsto:12345"); Intent smsIntent = new Intent(Intent.ACTION_SENDTO, smsUri); PackageManager smspackageManager = context.getPackageManager(); List<ResolveInfo> smsresolveInfos = smspackageManager.queryIntentActivities(smsIntent, 0); if (smsresolveInfos.size() > 0) { return true; } else { return false; } }
From source file:Main.java
/** * Open Play Store application or its web version if no play store * available./*from w w w . ja v a2s . c om*/ * * @param c : Android Context */ public static void actionDisplayPlayStore(Context c) { // Retrieve list of application that understand market Intent Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("market://details?id=org.alfresco.mobile.android.application")); final PackageManager mgr = c.getPackageManager(); List<ResolveInfo> list = mgr.queryIntentActivities(intent, 0); // By default we redirect to the webbrowser version of play store. intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("https://play.google.com/")); for (ResolveInfo resolveInfo : list) { // If we find something related to android we open the application // version of play store. if (resolveInfo.activityInfo.applicationInfo.packageName.contains("android")) { intent.setComponent(new ComponentName(resolveInfo.activityInfo.applicationInfo.packageName, resolveInfo.activityInfo.name)); intent.setData(Uri.parse("market://")); break; } } c.startActivity(intent); }
From source file:Main.java
public static void mail(Activity activity, String email, String subject, String content) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_EMAIL, new String[] { email }); intent.putExtra(Intent.EXTRA_SUBJECT, subject); if (content != null) { intent.putExtra(Intent.EXTRA_TEXT, content); }/* w w w. ja va 2 s. c o m*/ final PackageManager manager = activity.getPackageManager(); final List<ResolveInfo> matches = manager.queryIntentActivities(intent, 0); for (ResolveInfo info : matches) { if (info.activityInfo.packageName.endsWith(".gm") || info.activityInfo.name.toLowerCase().contains("gmail")) { intent.setClassName(info.activityInfo.packageName, info.activityInfo.name); } else if (info.activityInfo.packageName.endsWith(".email") || info.activityInfo.name.toLowerCase().contains("email")) { intent.setClassName(info.activityInfo.packageName, info.activityInfo.name); } } activity.startActivity(intent); }
From source file:Main.java
/** * Try to pick the app to handle this intent. * @param context/*from w w w . ja v a 2 s .c o m*/ * @param intent * @param matchMe E.g. "twitter" Pick the first app whose name contains this. * Can be null for pick-anything. * @return true if a match was found */ public static boolean pickIntentHandler(Context context, Intent intent, String matchMe) { final PackageManager pm = context.getPackageManager(); final List<ResolveInfo> activityList = pm.queryIntentActivities(intent, 0); List<String> handlers = new ArrayList(activityList.size()); for (ResolveInfo app : activityList) { String name = app.activityInfo.name; handlers.add(name); if (matchMe == null || name.contains(matchMe)) { ActivityInfo activity = app.activityInfo; ComponentName compname = new ComponentName(activity.applicationInfo.packageName, activity.name); // intent.addCategory(Intent.CATEGORY_LAUNCHER); // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); intent.setComponent(compname); return true; } } Log.d("pick-intent", "No match for " + matchMe + " in " + handlers); return false; }
From source file:Main.java
/** * This allows the app to specify a {@code packageName} to handle the {@code intent}, if the * {@code packageName} is available on the device and can handle it. An example use is to open * a Google + stream directly using the Google + app. *//* w ww .ja v a2 s . c o m*/ public static void preferPackageForIntent(Context context, Intent intent, String packageName) { PackageManager pm = context.getPackageManager(); if (pm != null) { for (ResolveInfo resolveInfo : pm.queryIntentActivities(intent, 0)) { if (resolveInfo.activityInfo.packageName.equals(packageName)) { intent.setPackage(packageName); break; } } } }
From source file:Main.java
/** Launch a SMS intent if the device is capable. * * @param activity The parent activity (for context) * @param number The number to sms (not the full URI) * @param text The sms body//from w ww. j a va2s .c om */ public static void launchSmsIntent(final Activity activity, String number, String text) { Log.i(LOG_TAG, "Launch SMS intent to " + number); // create sms intent Uri smsUri = Uri.parse("smsto:" + number); Intent smsIntent = new Intent(Intent.ACTION_SENDTO, smsUri); smsIntent.putExtra("sms_body", text); // make sure there is an activity which can handle the intent. PackageManager smspackageManager = activity.getPackageManager(); List<ResolveInfo> smsresolveInfos = smspackageManager.queryIntentActivities(smsIntent, 0); if (smsresolveInfos.size() > 0) { activity.startActivity(smsIntent); } }
From source file:Main.java
/** Launch an email intent if the device is capable. * * @param activity The parent activity (for context) * @param addr The address to email (not the full URI) * @param text The email body//from w w w. j a va2 s . com */ public static void launchEmailIntent(final Activity activity, String addr, String text) { Log.i(LOG_TAG, "Launch email intent from " + activity.getLocalClassName()); // create email intent Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { addr }); emailIntent.setType("text/plain"); // make sure there is an activity which can handle the intent. PackageManager emailpackageManager = activity.getPackageManager(); List<ResolveInfo> emailresolveInfos = emailpackageManager.queryIntentActivities(emailIntent, 0); if (emailresolveInfos.size() > 0) { activity.startActivity(emailIntent); } }