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

@TargetApi(Build.VERSION_CODES.M)
public static List<String> getCustomTabSupportingPackages(Context context) {
    PackageManager pm = context.getPackageManager();
    Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
    // Get all apps that can handle VIEW intents.
    List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, PackageManager.MATCH_ALL);
    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);
        }/*from   w  w w  .  j a  v a  2  s  .co  m*/
    }
    return packagesSupportingCustomTabs;
}

From source file:Main.java

public static Intent openLink(String url) {
    return new Intent(Intent.ACTION_VIEW, Uri.parse(url));
}

From source file:Main.java

public static Intent sendSms(String to, String message) {
    final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + to));
    intent.putExtra("sms_body", message);
    return intent;
}

From source file:Main.java

public static void openGallery(Context pContext) {
    Intent galleryIntent = new Intent(Intent.ACTION_VIEW,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    pContext.startActivity(galleryIntent);
}

From source file:Main.java

public static void openBrowser(Context context, String url) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    context.startActivity(intent);//w w  w .  ja  va 2 s .co  m
}

From source file:Main.java

public static Intent getSysAppSearchIntent(String key) {
    return new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=" + key));
}

From source file:Main.java

public static Intent getVideoPlayerIntent(Context context, Uri uri) {
    return new Intent(Intent.ACTION_VIEW).setDataAndType(uri, "video/*");
}

From source file:Main.java

public static void openUrl(Context pContext, String pUrl) {
    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(pUrl));
    pContext.startActivity(browserIntent);
}

From source file:Main.java

/**
 * Install apk//from   w  w w.  ja  v a 2  s. co m
 */
public static void installApk(Context context, Uri file) {
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(file, "application/vnd.android.package-archive");
    context.startActivity(intent);
}

From source file:Main.java

public static void doItNow(@NonNull Context context, @NonNull String resource) {
    //If a link//ww  w .  ja v a2  s  .  c  o m
    if (resource.startsWith("http")) {
        //If an app
        if (resource.startsWith("http://play.google.com/store/apps/")
                || resource.startsWith("https://play.google.com/store/apps/")) {
            String id = resource.substring(resource.indexOf('/', 32));
            //Try, if the user does not have the store installed, launch as web link
            try {
                context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://" + id)));
            } catch (ActivityNotFoundException anfx) {
                context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(resource)));
            }
        }
        //Otherwise opened with the browser
        else {
            Uri uri = Uri.parse(resource);
            context.startActivity(new Intent(Intent.ACTION_VIEW, uri));
        }
    }
}