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:com.danielhalupka.imageviewer.ImageViewer.java

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    try {// w w w  .  ja  va  2s  .  co  m
        if (ACTION_VIEW_IMAGE.equals(action)) {
            JSONObject arg_object = args.getJSONObject(0);
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            String filePath = arg_object.getString("filepath");
            intent.setDataAndType(Uri.parse(filePath), "image/*");
            this.cordova.getActivity().startActivity(intent);
            callbackContext.success();
            return true;
        }
        callbackContext.error("Invalid action");
        return false;
    } catch (JSONException e) {
        System.err.println("Exception: " + e.getMessage());
        callbackContext.error(e.getMessage());
        return false;
    }
}

From source file:Main.java

/**
 * Show a level//  w ww .  ja  va 2  s  . c o  m
 * 
 * @param context The context
 * @param level The level
 */
public static void showLevel(Context context, int level) {
    String filename;
    switch (level) {
    case 1: {
        filename = "ground_floor.png";
        break;
    }
    case 2: {
        filename = "talks_floor.png";
        break;
    }

    default: {
        return;
    }
    }
    File f = new File(context.getFilesDir() + "/" + filename);
    try {
        if (f.exists() == false) {
            InputStream is = context.getAssets().open(filename);
            FileOutputStream fos = context.openFileOutput(filename, Context.MODE_WORLD_READABLE);
            byte[] buffer = new byte[is.available()];
            is.read(buffer);
            // write the stream to file
            fos.write(buffer, 0, buffer.length);
            fos.close();
            is.close();
        }

        // Prepare the intent
        //TODO - create an activity for this instead. Internal viewers might be quite heavy
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(f), "image/png");
        context.startActivity(intent);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

/**
 * Open an URL in a message.//w w w  .  j  av a  2s  .c  o m
 *
 * This is intended to mirror the operation of the original
 * (see android.webkit.CallbackProxy) with one addition of intent flags
 * "FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET".  This improves behavior when sublaunching
 * other apps via embedded URI's.
 *
 * We also use this hook to catch "mailto:" links and handle them locally.
 *
 * @param activity parent activity
 * @param url URL to open
 * @param senderAccountId if the URL is mailto:, we use this account as the sender.
 *        TODO When MessageCompose implements the account selector, this won't be necessary.
 *        Pass {@link Account#NO_ACCOUNT} to use the default account.
 * @return true if the URI has successfully been opened.
 */
public static boolean openUrlInMessage(Activity activity, String url, long senderAccountId) {
    // hijack mailto: uri's and handle locally
    //***
    //if (url != null && url.toLowerCase().startsWith("mailto:")) {
    //    return MessageCompose.actionCompose(activity, url, senderAccountId);
    //}

    // Handle most uri's via intent launch
    boolean result = false;
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.addCategory(Intent.CATEGORY_BROWSABLE);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, activity.getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    try {
        activity.startActivity(intent);
        result = true;
    } catch (ActivityNotFoundException ex) {
        // No applications can handle it.  Ignore.
    }
    return result;
}

From source file:com.George.iexpense.activity.Echo.java

private PluginResult openFile(String fileUrl) {
    Log.d("FileViewerPlugin", "View file" + fileUrl);
    Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    File file = new File(fileUrl);
    String extension = fileUrl.substring(fileUrl.lastIndexOf(".") + 1);
    String type = "";
    if (extension.toLowerCase().equals("pdf")) {
        type = "application/pdf";
    } else if (extension.toLowerCase().equals("flv")) {
        type = "video/flv";
    } else if (extension.toLowerCase().equals("mp4")) {
        type = "video/mp4";
    } else if (extension.toLowerCase().equals("jpg")) {
        type = "image/jpg";
    }//from ww w  .ja va  2 s . c o m
    intent.setDataAndType(Uri.fromFile(file), type);
    cordova.getActivity().startActivity(intent);
    Log.d("FileViewerPlugin", "View complete in" + fileUrl);
    return new PluginResult(PluginResult.Status.OK, fileUrl);
}

From source file:Main.java

/**
 * Make UI TextView a html link./*from  w w w. j a v  a2  s  .  c o  m*/
 * 
 * @param context the context
 * @param textView the text view
 * @param html the html containing link info
 */
public static void makeTextViewAHTMLLink(final Context context, TextView textView, String html) {
    textView.setLinksClickable(true);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    CharSequence sequence = Html.fromHtml(html);
    SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(sequence);
    URLSpan[] urls = spannableStringBuilder.getSpans(0, sequence.length(), URLSpan.class);
    for (final URLSpan urlSpan : urls) {
        int start = spannableStringBuilder.getSpanStart(urlSpan);
        int end = spannableStringBuilder.getSpanEnd(urlSpan);
        int flags = spannableStringBuilder.getSpanFlags(urlSpan);
        ClickableSpan clickable = new ClickableSpan() {
            public void onClick(View view) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlSpan.getURL()));
                context.startActivity(intent);
            }

            @Override
            public void updateDrawState(TextPaint textPaint) {
                super.updateDrawState(textPaint);
                textPaint.setUnderlineText(false);
            }
        };
        spannableStringBuilder.removeSpan(urlSpan);
        spannableStringBuilder.setSpan(clickable, start, end, flags);
    }
    textView.setText(spannableStringBuilder);
}

From source file:com.theelix.libreexplorer.FileManager.java

/**
 * This method chooses the appropriate Apps and Open the file
 *
 * @param file The target file//from   w  ww . ja v  a 2 s.com
 */
public static void openFile(File file) {
    try {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        Uri uri = Uri.fromFile(file);
        String mimeType = FileUtilties.getMimeType(uri);
        if (mimeType == null) {
            mimeType = "*/*";
        }
        intent.setDataAndType(uri, mimeType);
        mContext.startActivity(Intent.createChooser(intent, null));
    } catch (ActivityNotFoundException e) {
        //Activity is not found so App'll start an intent with generic Mimetype
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        Uri uri = Uri.fromFile(file);
        intent.setDataAndType(uri, "*/*");
        mContext.startActivity(Intent.createChooser(intent, null));
    }

}

From source file:be.ac.ucl.lfsab1509.llncampus.ExternalAppUtility.java

/** 
 * Open a browser with the URI specified.
 * /*  w w  w .ja v a2s  .com*/
 * @param context 
 *          Application context. 
 * @param uri 
 *          The URI.
 */
public static void openBrowser(Context context, Uri uri) {
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    context.startActivity(intent);
}

From source file:MainActivity.java

public void launchIntent(View view) {
    Log.i("MainActivity", "launchIntent()");
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("https://www.java2s.com/"));
    startActivity(intent);//from   www  .  j  ava 2 s . c  o m
}

From source file:com.apptentive.android.sdk.module.engagement.interaction.view.NavigateToLinkInteractionView.java

@Override
public void doOnCreate(Activity activity, Bundle savedInteraction) {
    boolean success = false;
    try {/*from   w w  w. j  a v  a  2s .com*/
        String url = interaction.getUrl();
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));

        switch (interaction.getTarget()) {
        case New:
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            break;
        case Self:
            // Nothing
            break;
        default:
            break;
        }

        activity.startActivity(intent);
        success = true;
    } catch (ActivityNotFoundException e) {
        Log.w("NavigateToLink Error: ", e);
    } finally {
        JSONObject data = new JSONObject();
        try {
            data.put(NavigateToLinkInteraction.KEY_URL, interaction.getUrl());
            data.put(NavigateToLinkInteraction.KEY_TARGET, interaction.getTarget().lowercaseName());
            data.put(NavigateToLinkInteraction.EVENT_KEY_SUCCESS, success);
        } catch (JSONException e) {
            Log.e("Error creating Event data object.", e);
        }
        EngagementModule.engageInternal(activity, interaction, NavigateToLinkInteraction.EVENT_NAME_NAVIGATE,
                data.toString());
        // Always finish this Activity.
        activity.finish();
    }
}

From source file:Main.java

public static void rateUs(String packageName) {
    if (packageName.isEmpty())
        packageName = mContext.getPackageName();
    String jumpUrl = "";
    Intent i = getIntent(mContext);/*  ww  w  . j a v  a  2 s  . c  o  m*/
    boolean b = judge(mContext, i);
    if (b == false) {
        String tGooglePlayNo = "https://play.google.com/store/apps/details?id=" + packageName;
        jumpUrl = tGooglePlayNo;
    } else {
        String tGooglePlayYes = "market://details?id=" + packageName;
        jumpUrl = tGooglePlayYes;
    }

    Uri uri = Uri.parse(jumpUrl);
    Intent it = new Intent(Intent.ACTION_VIEW, uri);
    mContext.startActivity(it);
}