List of usage examples for android.content Intent ACTION_VIEW
String ACTION_VIEW
To view the source code for android.content Intent ACTION_VIEW.
Click Source Link
From source file:Main.java
/** * Checks if there is any Pay by Bank app enabled CFI App installed on the device. * * @param context The context to use./*from w w w .j a va 2s .co m*/ * @return True if there is at least one PBBA enabled CFI App available, false otherwise. * @see #openBankingApp(Context, String) */ public static boolean isCFIAppAvailable(@NonNull final Context context) { //noinspection ConstantConditions if (context == null) { throw new IllegalArgumentException("context == null"); } final Intent zappIntent = new Intent(); zappIntent.setData(new Uri.Builder().scheme(ZAPP_SCHEME).build()); zappIntent.setAction(Intent.ACTION_VIEW); final ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(zappIntent, PackageManager.MATCH_DEFAULT_ONLY); return resolveInfo != null; }
From source file:Main.java
public static void openURL(String url) { if (url.isEmpty()) return;/* w ww .j av a2 s. co m*/ Uri uri = Uri.parse(url); Intent it = new Intent(Intent.ACTION_VIEW, uri); mContext.startActivity(it); }
From source file:Main.java
/** * Goes through all apps that handle VIEW intents and have a warmup service. Picks * the one chosen by the user if there is one, otherwise makes a best effort to return a * valid package name./*from w w w . j av a 2 s . c o m*/ * * This is <strong>not</strong> threadsafe. * * @param context {@link Context} to use for accessing {@link PackageManager}. * @return The package name recommended to use for connecting to custom tabs related components. */ public static String getPackageNameToUse(Context context) { if (sPackageNameToUse != null) return sPackageNameToUse; PackageManager pm = context.getPackageManager(); // Get default VIEW intent handler. Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0); String defaultViewHandlerPackageName = null; if (defaultViewHandlerInfo != null) { defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName; } // Get all apps that can handle VIEW intents. List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0); List<String> packagesSupportingCustomTabs = new ArrayList<>(); for (ResolveInfo info : resolvedActivityList) { Intent serviceIntent = new Intent(); serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION); serviceIntent.setPackage(info.activityInfo.packageName); if (pm.resolveService(serviceIntent, 0) != null) { packagesSupportingCustomTabs.add(info.activityInfo.packageName); } } // Now packagesSupportingCustomTabs contains all apps that can handle both VIEW intents // and service calls. if (packagesSupportingCustomTabs.isEmpty()) { sPackageNameToUse = null; } else if (packagesSupportingCustomTabs.size() == 1) { sPackageNameToUse = packagesSupportingCustomTabs.get(0); } else if (!TextUtils.isEmpty(defaultViewHandlerPackageName) && !hasSpecializedHandlerIntents(context, activityIntent) && packagesSupportingCustomTabs.contains(defaultViewHandlerPackageName)) { sPackageNameToUse = defaultViewHandlerPackageName; } else if (packagesSupportingCustomTabs.contains(STABLE_PACKAGE)) { sPackageNameToUse = STABLE_PACKAGE; } else if (packagesSupportingCustomTabs.contains(BETA_PACKAGE)) { sPackageNameToUse = BETA_PACKAGE; } else if (packagesSupportingCustomTabs.contains(DEV_PACKAGE)) { sPackageNameToUse = DEV_PACKAGE; } else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) { sPackageNameToUse = LOCAL_PACKAGE; } return sPackageNameToUse; }
From source file:Main.java
public static void viewUriForMimeType(Context context, Uri uri, String type) { Intent intent;//from w w w.ja v a 2 s .co m intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); if (type == null) intent.setData(uri); else intent.setDataAndType(uri, type); context.startActivity(intent); }
From source file:Main.java
public static void shareOnFacebook(Context pContext, String urlToShare) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); // intent.putExtra(Intent.EXTRA_SUBJECT, "Foo bar"); // NB: has no effect! intent.putExtra(Intent.EXTRA_TEXT, urlToShare); // See if official Facebook app is found boolean facebookAppFound = false; List<ResolveInfo> matches = pContext.getPackageManager().queryIntentActivities(intent, 0); for (ResolveInfo info : matches) { if (info.activityInfo.packageName.toLowerCase().startsWith("com.facebook.katana")) { intent.setPackage(info.activityInfo.packageName); facebookAppFound = true;/*from w ww .ja v a 2 s. c o m*/ break; } } // As fallback, launch sharer.php in a browser if (!facebookAppFound) { String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare; intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl)); } pContext.startActivity(intent); }
From source file:com.phonegap.plugins.openfilewithexternalapp.OpenFileWithExternalApp.java
public PluginResult execute(String action, JSONArray args, String callbackId) { try {/*from w w w. ja v a 2 s. co m*/ String filePath = args.getString(0); Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); File fileToOpen = new File(filePath); MimeTypeMap mime = MimeTypeMap.getSingleton(); String extension = fileToOpen.getName().substring(fileToOpen.getName().lastIndexOf(".") + 1) .toLowerCase(); String type = mime.getMimeTypeFromExtension(extension); intent.setAction(Intent.ACTION_VIEW); Uri uri = Uri.fromFile(fileToOpen); intent.setDataAndType(uri, type); this.ctx.startActivity(intent); } catch (JSONException e) { e.printStackTrace(); } PluginResult mPlugin = new PluginResult(PluginResult.Status.NO_RESULT); return mPlugin; }
From source file:Main.java
private static void startViewUri(Context context, String uri) { context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(uri))); }
From source file:net.reichholf.dreamdroid.intents.IntentFactory.java
public static Intent getStreamServiceIntent(String ref, String title) { Intent intent = new Intent(Intent.ACTION_VIEW); String uriString = SimpleHttpClient.getInstance().buildServiceStreamUrl(ref, title); Log.i(DreamDroid.LOG_TAG, "Service-Streaming URL set to '" + uriString + "'"); intent.setDataAndType(Uri.parse(uriString), "video/*"); intent.putExtra("title", title); return intent; }
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;/*from w w w . j a v a 2 s .com*/ 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
/******************* * PRIVATE METHODS *// ww w . j a va 2 s. c o m *******************/ private static boolean urlCanBeHandled(Context aContext, String aURLString) { PackageManager packageManager = aContext.getPackageManager(); Intent openAppIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(aURLString)); List activitiesCanHandle = packageManager.queryIntentActivities(openAppIntent, PackageManager.MATCH_DEFAULT_ONLY); return activitiesCanHandle.size() != 0; }