List of usage examples for android.content.pm PackageManager queryIntentActivities
public abstract List<ResolveInfo> queryIntentActivities(Intent intent, @ResolveInfoFlags int flags);
From source file:com.todoroo.astrid.actfm.ActFmCameraModule.java
public static void showPictureLauncher(final Fragment fragment, final ClearImageCallback clearImageOption) { ArrayList<String> options = new ArrayList<String>(); final Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); PackageManager pm = fragment.getActivity().getPackageManager(); final boolean cameraAvailable = pm.queryIntentActivities(cameraIntent, 0).size() > 0; if (cameraAvailable) options.add(fragment.getString(R.string.actfm_picture_camera)); options.add(fragment.getString(R.string.actfm_picture_gallery)); if (clearImageOption != null) options.add(fragment.getString(R.string.actfm_picture_clear)); ArrayAdapter<String> adapter = new ArrayAdapter<String>(fragment.getActivity(), android.R.layout.simple_spinner_dropdown_item, options.toArray(new String[options.size()])); DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { @SuppressWarnings("nls") @Override/*from w w w .j a v a 2s.c o m*/ public void onClick(DialogInterface d, int which) { if (which == 0 && cameraAvailable) { lastTempFile = getTempFile(fragment.getActivity()); if (lastTempFile != null) cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(lastTempFile)); fragment.startActivityForResult(cameraIntent, REQUEST_CODE_CAMERA); } else if ((which == 1 && cameraAvailable) || (which == 0 && !cameraAvailable)) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); fragment.startActivityForResult( Intent.createChooser(intent, fragment.getString(R.string.actfm_TVA_tag_picture)), REQUEST_CODE_PICTURE); } else { if (clearImageOption != null) clearImageOption.clearImage(); } } }; // show a menu of available options new AlertDialog.Builder(fragment.getActivity()).setAdapter(adapter, listener).show() .setOwnerActivity(fragment.getActivity()); }
From source file:codepath.watsiapp.utils.Util.java
private static void startShareIntentWithExplicitSocialActivity(Activity ctx, ShareableItem patient, Set<String> socialActivitiesName, String displayName) { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setType("text/plain"); shareIntent.putExtra(Intent.EXTRA_TEXT, patient.getShareableUrl()); try {// w w w .j a va2s . c o m final PackageManager pm = ctx.getPackageManager(); final List activityList = pm.queryIntentActivities(shareIntent, 0); int len = activityList.size(); for (int i = 0; i < len; i++) { final ResolveInfo app = (ResolveInfo) activityList.get(i); Log.d("#####################", app.activityInfo.name); if (socialActivitiesName.contains(app.activityInfo.name)) { final ActivityInfo activity = app.activityInfo; final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name); shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Fund Treatment"); shareIntent.addCategory(Intent.CATEGORY_LAUNCHER); shareIntent.setComponent(name); ctx.startActivity(shareIntent); break; } } } catch (final ActivityNotFoundException e) { Toast.makeText(ctx, "Could not find " + displayName + " app", Toast.LENGTH_SHORT).show(); } }
From source file:com.binomed.showtime.android.util.CineShowTimeLayoutUtils.java
public static void manageVisibiltyFieldSpeech(Context context, ImageButton button, AutoCompleteTextView text, int idRightof, int idLeftOf, int idBelow) { // Manage speech button just if package present on device PackageManager pm = context.getPackageManager(); List<ResolveInfo> activities = pm .queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); if (activities.size() == 0) { button.setVisibility(View.GONE); if ((text != null) && (Integer.valueOf(Build.VERSION.SDK) <= 3)) { // Manage specificity for version before 4 RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); if (idRightof != -1) { params.addRule(RelativeLayout.RIGHT_OF, idRightof); }/*from ww w . j a v a 2 s . c o m*/ if (idLeftOf != -1) { params.addRule(RelativeLayout.LEFT_OF, idLeftOf); } if (idBelow != -1) { params.addRule(RelativeLayout.BELOW, idBelow); } text.setSingleLine(true); text.setLayoutParams(params); } } }
From source file:android.support.customtabs.browseractions.BrowserActionsIntent.java
/** * Check whether any Browser Actions provider is available to handle the {@link * BrowserActionsIntent}./*from w ww. j a v a 2s . co m*/ * @param context The context requesting for a Browser Actions menu. * @return true If a Browser Actions provider is available handle the intent. */ private static boolean hasBrowserActionsIntentHandler(Context context) { Intent intent = new Intent(BrowserActionsIntent.ACTION_BROWSER_ACTIONS_OPEN, Uri.parse(TEST_URL)); PackageManager pm = context.getPackageManager(); List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(intent, PackageManager.MATCH_ALL); return resolveInfoList.size() > 0 ? true : false; }
From source file:Main.java
public static void openMailChooser(Context context, String text, String[] mails, String subject) { Intent mailIntent = new Intent(); mailIntent.setAction(Intent.ACTION_SEND); mailIntent.putExtra(Intent.EXTRA_TEXT, text); mailIntent.putExtra(Intent.EXTRA_EMAIL, mails); mailIntent.putExtra(Intent.EXTRA_SUBJECT, subject); mailIntent.setType(INTENT_TYPE_MSG); PackageManager pm = context.getPackageManager(); Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.setType(INTENT_TYPE_TEXT); Intent openInChooser = Intent.createChooser(mailIntent, ""); List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0); List<LabeledIntent> intentList = new ArrayList<LabeledIntent>(); for (ResolveInfo ri : resInfo) { String packageName = ri.activityInfo.packageName; if (packageName.contains(PACKAGE_EMAIL)) { mailIntent.setPackage(packageName); } else if (packageName.contains(PACKAGE_MMS) || packageName.contains(PACKAGE_GMAIL)) { Intent intent = new Intent(); intent.setComponent(new ComponentName(packageName, ri.activityInfo.name)); intent.setAction(Intent.ACTION_SEND); intent.setType(INTENT_TYPE_TEXT); if (packageName.contains(PACKAGE_MMS)) { intent.putExtra("subject", subject); intent.putExtra("sms_body", text); intent.putExtra("address", mails[0]); intent.setType(INTENT_TYPE_MSG); } else if (packageName.contains(PACKAGE_GMAIL)) { intent.putExtra(Intent.EXTRA_TEXT, text); intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.putExtra(Intent.EXTRA_EMAIL, mails); intent.setType(INTENT_TYPE_MSG); }/*from www .j av a 2s. com*/ intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon)); } } LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]); openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents); context.startActivity(openInChooser); }
From source file:com.github.javiersantos.piracychecker.LibraryUtils.java
private static boolean isIntentAvailable(Context ctx, Intent intent) { final PackageManager mgr = ctx.getPackageManager(); List<ResolveInfo> list = mgr.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return list != null && list.size() > 0; }
From source file:Main.java
public static boolean isApkInstalled(Context context) { PackageManager pm = context.getPackageManager(); // Intent intent = new Intent(Intent.ACTION_MAIN, null); // intent.addCategory(Intent.CATEGORY_DEFAULT); // intent.setPackage("com.cnnct.zfwgpy"); Intent intent = new Intent(); intent.setPackage("com.cnnct.zfwgpy"); List<ResolveInfo> apps = pm.queryIntentActivities(intent, 0); if (apps != null && apps.size() > 0) { return true; }/*from ww w. j a v a2 s.com*/ return false; }
From source file:Main.java
public static void startApkActivity(final Context ctx, String packageName) { PackageManager pm = ctx.getPackageManager(); PackageInfo pi;// ww w.j a va2 s . com try { pi = pm.getPackageInfo(packageName, 0); Intent intent = new Intent(Intent.ACTION_MAIN, null); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setPackage(pi.packageName); List<ResolveInfo> apps = pm.queryIntentActivities(intent, 0); ResolveInfo ri = apps.iterator().next(); if (ri != null) { String className = ri.activityInfo.name; intent.setComponent(new ComponentName(packageName, className)); ctx.startActivity(intent); } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } }
From source file:Main.java
public static void startApkActivity(final Context ctx, String packageName) { PackageManager pm = ctx.getPackageManager(); PackageInfo pi;//from ww w. ja va 2 s.co m try { pi = pm.getPackageInfo(packageName, 0); Intent intent = new Intent(Intent.ACTION_MAIN, null); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setPackage(pi.packageName); List<ResolveInfo> apps = pm.queryIntentActivities(intent, 0); ResolveInfo ri = apps.iterator().next(); if (ri != null) { String className = ri.activityInfo.name; intent.setComponent(new ComponentName(packageName, className)); ctx.startActivity(intent); } } catch (NameNotFoundException e) { e.printStackTrace(); } }
From source file:at.wada811.utils.IntentUtils.java
/** * Intent??Activity?/*from w w w.j a v a2s . com*/ * * @param context * @param intent * @return */ public static List<ResolveInfo> queryIntentActivities(Context context, Intent intent) { PackageManager packageManager = context.getPackageManager(); return packageManager.queryIntentActivities(intent, 0); }