Example usage for android.content Intent ACTION_VIEW

List of usage examples for android.content Intent ACTION_VIEW

Introduction

In this page you can find the example usage for android.content Intent ACTION_VIEW.

Prototype

String ACTION_VIEW

To view the source code for android.content Intent ACTION_VIEW.

Click Source Link

Document

Activity Action: Display the data to the user.

Usage

From source file:Main.java

public static void openUrl(Context context, String url) {
    String urlLower = url.toLowerCase();
    if (!urlLower.startsWith("http"))
        url = "http://" + url;

    Uri uri = Uri.parse(url);/*w w w. ja  v  a  2  s  .  co  m*/
    Intent i = new Intent(Intent.ACTION_VIEW, uri);
    context.startActivity(i);
}

From source file:Main.java

public static void openURL(final Context ctx, final String url) {
    final Intent i2 = new Intent(Intent.ACTION_VIEW);
    i2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i2.setData(Uri.parse(url));//from w w  w  .j ava2  s . com
    ctx.startActivity(i2);
}

From source file:Main.java

public static void showExamInBrowser(Context context, String courseId) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(URL_GET_EXAMS));
    context.startActivity(intent);//w  w  w  .j  a  v  a  2  s . c  om
    // TODO: create activity with webview that uses stored credentials to login and open page with search for courseId
}

From source file:Main.java

/**
 * Creates an Intent to open Parche application and pass the required information to provide a user discount
 * along to the app.//from   w w  w. j  a v a2 s  .  c  o m
 *
 * @param aContext          The current context.
 * @param aDiscountCode     The discount code retrieved from the Parche server.
 * @param aPartnerUserID    The user ID to identify the user. NOTE: Will be url-encoded this
 *                          class, DO NOT URL ENCODE before passing in.
 * @param aAPIKey           The partner applications Parche API key.
 *
 * @return The intent to open the Parche application, or null if the app needs to be updated or installed.
 */
public static Intent openParcheAndRequestDiscount(Context aContext, String aDiscountCode, String aPartnerUserID,
        String aAPIKey) {
    Intent returnIntent = null;
    if (!parcheNeedsToBeUpdatedOrInstalled(aContext)) {
        String urlString = URL_SCHEME + OPEN_ENDPOINT
                + String.format(DISCOUNT_FORMAT, aPartnerUserID, aDiscountCode, aAPIKey);
        returnIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlString));
    }

    return returnIntent;
}

From source file:Main.java

/**
 * Open the specified map in Collector for ArcGIS.
 *
 * @param activity  the activity launching Collector for ArcGIS.
 * @param mapItemId The web map item ID to open within Collector.
 * @param mapCenter Specified as a set of latitude, longitude (y,x) coordinates. Coordinates must be in WGS84 coordinates. (optional)
 * @throws IllegalArgumentException if the map item id passed in is null or empty
 *///from w ww  . j  a  va  2s  .  c  o m
public static void openMapInCollector(Activity activity, String mapItemId, String mapCenter) {
    Uri uriBuilder = generateUri(mapItemId, mapCenter);

    Intent mapIntent = new Intent(Intent.ACTION_VIEW, uriBuilder);
    activity.startActivity(mapIntent);
}

From source file:Main.java

/**
 * Save a media in the downloads directory and offer to open it with a third party application.
 * @param activity the activity/*  w  w w. j a  v a2  s.c  om*/
 * @param savedMediaPath the media path
 * @param mimeType the media mime type.
 */
public static void openMedia(final Activity activity, final String savedMediaPath, final String mimeType) {
    if ((null != activity) && (null != savedMediaPath)) {
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                try {
                    File file = new File(savedMediaPath);
                    Intent intent = new Intent();
                    intent.setAction(android.content.Intent.ACTION_VIEW);
                    intent.setDataAndType(Uri.fromFile(file), mimeType);
                    activity.startActivity(intent);
                } catch (ActivityNotFoundException e) {
                    Toast.makeText(activity, e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
                } catch (Exception e) {
                }
            }
        });
    }
}

From source file:Main.java

public static boolean openURL(String url) {
    boolean ret = false;
    try {/*from  w  w w.  j  av a  2  s .co m*/
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        sActivity.startActivity(i);
        ret = true;
    } catch (Exception e) {
    }
    return ret;
}

From source file:Main.java

/**
 * Launches the Play Store product page for the specified package name
 *
 * @param context/*from  w w w  . j a v  a 2s. c o  m*/
 * @param packageName The package name of the app
 */
public static void launchPlayStoreProductPage(Context context, String packageName) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    try {
        intent.setData(Uri.parse("market://details?id=" + packageName));
        context.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        intent.setData(Uri.parse("http://play.google.com/store/apps/details?id=" + packageName));
        context.startActivity(intent);
    }
}

From source file:Main.java

/**
 * Launches the URI specified.// www  .jav a 2s . co  m
 *
 * @param context
 * @param uri The URI to launch.
 * @return <b>true</b> if the URI is valid and there are available apps to handle it, <b>false</b> otherwise
 */
public static boolean launchURI(Context context, String uri) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
    try {
        context.startActivity(intent);
        return true;
    } catch (ActivityNotFoundException e) {
        return false;
    }
}

From source file:Main.java

public static Intent getApplicationDetailsIntent(String packageName) {

    Intent intent = new Intent();
    final int apiLevel = Build.VERSION.SDK_INT;

    if (apiLevel >= 9) { // above 2.3
        intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
        Uri uri = Uri.fromParts(SCHEME, packageName, null);
        intent.setData(uri);// w w  w . j av  a2s  .c om
    } else { // below 2.3
        final String appPkgName = (apiLevel == 8 ? APP_PKG_NAME_22 : APP_PKG_NAME_21);
        intent.setAction(Intent.ACTION_VIEW);
        intent.setClassName(APP_DETAILS_PACKAGE_NAME, APP_DETAILS_CLASS_NAME);
        intent.putExtra(appPkgName, packageName);
    }
    return intent;
}