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 boolean isCallable(Context context, String url) {
    String mimeTypeExtension = URLConnection.guessContentTypeFromName(url);

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.parse(url), mimeTypeExtension);
    List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

From source file:Main.java

public static void launchUri(Context context, Uri uri) {
    context.startActivity(new Intent(Intent.ACTION_VIEW, uri));
}

From source file:Main.java

/**
 * Simply opens browser with a regular intent.
 * //w  w  w .  jav a 2  s  .  co m
 * @param ctx
 *            context to use
 * @param uri
 *            url top open
 */
public static void open(final Context ctx, final String uri) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(uri));
    ctx.startActivity(intent);
}

From source file:Main.java

@SuppressLint("InlinedApi")
public static void openSys(Context context, String packageName) {
    Intent intent = new Intent();
    final int apiLevel = Build.VERSION.SDK_INT;
    if (apiLevel >= 9) {
        intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        intent.setData(Uri.fromParts("package", packageName, null));
    } else {//from  ww  w .j  a  v  a2s. c o m
        intent.setAction(Intent.ACTION_VIEW);
        intent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
        String appPkgName = (apiLevel == 8 ? "pkg" : "com.android.settings.ApplicationPkgName");
        intent.putExtra(appPkgName, packageName);
    }
    context.startActivity(intent);
}

From source file:Main.java

public static void startMarket(Context context, String packageName, String referrer) {
    String referrerParam = referrer != null ? "&referrer=" + referrer : "";
    try {//from   www .ja  va 2  s.  co m
        Uri uri = Uri.parse("market://details?id=" + packageName + referrerParam);
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    } catch (ActivityNotFoundException anfe) {
        Intent intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("https://play.google.com/store/apps/details?id=" + packageName + referrerParam));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }
}

From source file:Main.java

/**
 * Opens browser with special flags for no history/recents/etc
 * //w w w  . jav a  2 s  .com
 * @param ctx
 *            context to use
 * @param url
 *            url to open
 */
public static void openNoHistory(Context ctx, String url) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(url));
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    ctx.startActivity(intent);
}

From source file:Main.java

private static void syncContactHiResPhoto(Context context, long rawContactId) {
    final String serviceName = "com.google.android.syncadapters.contacts." + "SyncHighResPhotoIntentService";
    final String servicePackageName = "com.google.android.syncadapters.contacts";
    final Uri uri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
    final Intent intent = new Intent();
    intent.setClassName(servicePackageName, serviceName);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(uri, RawContacts.CONTENT_ITEM_TYPE);
    try {// www  .  j  av a 2s  .  c o  m
        context.startService(intent);
    } catch (Exception e) {

    }
}

From source file:Main.java

/**
 * Returns an intent to display the message identified by the provided URI in K-9 Mail.
 *
 * @param context// w  w w. j  ava 2s . c o  m
 *         Used to retrieve the package manager.
 * @param emailUri
 *         The URI that identified the message to be displayed.
 *
 * @return An intent to start K-9 Mail's main activity, or {@code null} in case of an error.
 */
public static final Intent getViewMessageIntent(Context context, String emailUri) {
    try {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setPackage(PACKAGE_NAME);
        intent.setData(Uri.parse(emailUri));
        return intent;
    } catch (Exception e) {
        return null;
    }
}

From source file:Main.java

public static void setClickable(final TextView textView) {
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    Spannable sp = (Spannable) textView.getText();
    ImageSpan[] images = sp.getSpans(0, textView.getText().length(), ImageSpan.class);

    for (ImageSpan span : images) {
        final String image_src = span.getSource();
        final int start = sp.getSpanStart(span);
        final int end = sp.getSpanEnd(span);

        ClickableSpan click_span = new ClickableSpan() {
            @Override//from w w w.  ja  v  a2 s .  co  m
            public void onClick(View widget) {
                String[] strs = image_src.split("/");
                String filePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/LilyClient/"
                        + strs[strs.length - 2] + "-" + strs[strs.length - 1];

                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.setType("image/*");
                intent.setDataAndType(Uri.fromFile(new File(filePath)), "image/*");
                textView.getContext().startActivity(intent);

            }
        };
        ClickableSpan[] click_spans = sp.getSpans(start, end, ClickableSpan.class);
        if (click_spans.length != 0) {
            for (ClickableSpan c_span : click_spans) {
                sp.removeSpan(c_span);
            }
        }
        sp.setSpan(click_span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}

From source file:Main.java

/**
 * Open Play Store application or its web version if no play store
 * available./*from w w  w .  j  av  a2  s  .c o m*/
 * 
 * @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);
}