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 install(Context context, File file) {
    try {//w  ww  . j  av a 2s . c om
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
        context.startActivity(intent);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void openAppInGooglePlay(Context pContext, String pPackageName) {
    try {//from   w ww .  j  av a  2  s . c o m
        pContext.startActivity(
                new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + pPackageName)));
    } catch (android.content.ActivityNotFoundException anfe) {
        pContext.startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse("https://play.google.com/store/apps/details?id=" + pPackageName)));
    }
}

From source file:Main.java

public static AlertDialog showTutorialDialog(final Context context) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle("Watch a YouTube video tutorial?");
    builder.setIcon(android.R.drawable.ic_dialog_info);
    builder.setPositiveButton("Watch", new DialogInterface.OnClickListener() {
        @Override//from  ww w.jav  a 2 s . c om
        public void onClick(DialogInterface dialog, int which) {
            PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("firstrun", false)
                    .commit();
            Intent browserIntent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://www.youtube.com/watch?v=LhiSWE5-ezM"));
            context.startActivity(browserIntent);
        }
    });

    builder.setNeutralButton("Close", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("firstrun", false)
                    .commit();
            dialog.dismiss();
        }
    });
    AlertDialog alert = builder.create();
    alert.show();

    return alert;
}

From source file:Main.java

public static void disImage(Activity act, File file) {
    Intent itt = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    itt.setData(Uri.fromFile(file));// www  .  j a va2  s.co m
    act.sendBroadcast(itt);

    Intent it = new Intent(Intent.ACTION_VIEW);
    it.setDataAndType(Uri.parse(file.getPath()), "image/*");
    act.startActivity(it);
}

From source file:Main.java

public static void installApk(Context context, Uri file) {
    if (context == null)
        return;//w ww.  j  av a 2  s  .  c o  m
    if (file == null)
        return;
    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

private static AlertDialog showDownloadDialog(final Activity activity, CharSequence stringTitle,
        CharSequence stringMessage, CharSequence stringButtonYes, CharSequence stringButtonNo,
        final String uriString) {
    AlertDialog.Builder downloadDialog = new AlertDialog.Builder(activity);
    downloadDialog.setTitle(stringTitle);
    downloadDialog.setMessage(stringMessage);
    downloadDialog.setPositiveButton(stringButtonYes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialogInterface, int i) {
            Uri uri = Uri.parse(uriString);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            activity.startActivity(intent);
        }//from www.java 2 s  .  c o m
    });
    downloadDialog.setNegativeButton(stringButtonNo, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialogInterface, int i) {
        }
    });
    return downloadDialog.show();
}

From source file:Main.java

public static Intent getOpenFileIntent(Uri uri, String mimeType) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(uri, mimeType);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    return intent;
}

From source file:Main.java

private static AlertDialog showDownloadDialog(final Activity activity, CharSequence stringTitle,
        CharSequence stringMessage, CharSequence stringButtonYes, CharSequence stringButtonNo) {
    AlertDialog.Builder downloadDialog = new AlertDialog.Builder(activity);
    downloadDialog.setTitle(stringTitle);
    downloadDialog.setMessage(stringMessage);
    downloadDialog.setPositiveButton(stringButtonYes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialogInterface, int i) {
            Uri uri = Uri.parse("market://search?q=pname:org.torproject.android");
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            activity.startActivity(intent);
        }//from w w w .  j a v a 2  s .c  o  m
    });
    downloadDialog.setNegativeButton(stringButtonNo, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialogInterface, int i) {
        }
    });
    return downloadDialog.show();
}

From source file:Main.java

public static Intent getLaunchIntent(Context context, String title, String url, String sel) {
    Intent intent = null;//from w w w .j av  a  2 s .c  om
    String number = parseTelephoneNumber(sel);
    if (number != null) {
        intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + number));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    } else {
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (isMapsURL(url)) {
            intent.setClassName(GMM_PACKAGE_NAME, GMM_CLASS_NAME);
        } else if (isYouTubeURL(url)) {
            intent.setPackage(YT_PACKAGE_NAME);
        }

        // Fall back if we can't resolve intent (i.e. app missing)
        PackageManager pm = context.getPackageManager();
        if (null == intent.resolveActivity(pm)) {
            intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
    }

    if (sel != null && sel.length() > 0) {
        ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
        cm.setText(sel);
    }

    return intent;
}

From source file:Main.java

public static void installApk(Context context, File file) {
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    context.startActivity(intent);// w  ww . j ava  2s. com
}