Example usage for android.content Intent setType

List of usage examples for android.content Intent setType

Introduction

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

Prototype

public @NonNull Intent setType(@Nullable String type) 

Source Link

Document

Set an explicit MIME data type.

Usage

From source file:com.github.chenxiaolong.dualbootpatcher.FileUtils.java

private static void setCommonSaveOptions(Intent intent, String mimeType, String defaultName) {
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType(mimeType);
    intent.putExtra(Intent.EXTRA_TITLE, defaultName);
}

From source file:Main.java

public static void sendEmail(Context ctx, String[] emailAddresses, String[] CCAddresses, String subject,
        String message) {/*from   w  w w  . j  a  va 2 s  .  c  o  m*/

    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    // emailIntent.setType("text/plain");
    emailIntent.setData(Uri.parse("mailto:"));
    String[] to = emailAddresses;
    String[] cc = CCAddresses;
    emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
    if (CCAddresses != null) {
        emailIntent.putExtra(Intent.EXTRA_CC, cc);
    }
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, message);
    emailIntent.setType("message/rfc822");

    ctx.startActivity(Intent.createChooser(emailIntent, "Email"));

}

From source file:com.wellsandwhistles.android.redditsp.reddit.api.RedditAPICommentAction.java

public static void onActionMenuItemSelected(final RedditRenderableComment renderableComment,
        final RedditCommentView commentView, final AppCompatActivity activity,
        final CommentListingFragment commentListingFragment, final RedditCommentAction action,
        final RedditChangeDataManager changeDataManager) {

    final RedditComment comment = renderableComment.getParsedComment().getRawComment();

    switch (action) {

    case UPVOTE://from   w w  w. j a v  a 2  s  .  c  om
        action(activity, comment, RedditAPI.ACTION_UPVOTE, changeDataManager);
        break;

    case DOWNVOTE:
        action(activity, comment, RedditAPI.ACTION_DOWNVOTE, changeDataManager);
        break;

    case UNVOTE:
        action(activity, comment, RedditAPI.ACTION_UNVOTE, changeDataManager);
        break;

    case SAVE:
        action(activity, comment, RedditAPI.ACTION_SAVE, changeDataManager);
        break;

    case UNSAVE:
        action(activity, comment, RedditAPI.ACTION_UNSAVE, changeDataManager);
        break;

    case REPORT:

        new AlertDialog.Builder(activity).setTitle(R.string.action_report)
                .setMessage(R.string.action_report_sure)
                .setPositiveButton(R.string.action_report, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        action(activity, comment, RedditAPI.ACTION_REPORT, changeDataManager);
                    }
                }).setNegativeButton(R.string.dialog_cancel, null).show();

        break;

    case REPLY: {
        final Intent intent = new Intent(activity, CommentReplyActivity.class);
        intent.putExtra(CommentReplyActivity.PARENT_ID_AND_TYPE_KEY, comment.getIdAndType());
        intent.putExtra(CommentReplyActivity.PARENT_MARKDOWN_KEY,
                StringEscapeUtils.unescapeHtml4(comment.body));
        activity.startActivity(intent);
        break;
    }

    case EDIT: {
        final Intent intent = new Intent(activity, CommentEditActivity.class);
        intent.putExtra("commentIdAndType", comment.getIdAndType());
        intent.putExtra("commentText", StringEscapeUtils.unescapeHtml4(comment.body));
        activity.startActivity(intent);
        break;
    }

    case DELETE: {
        new AlertDialog.Builder(activity).setTitle(R.string.accounts_delete).setMessage(R.string.delete_confirm)
                .setPositiveButton(R.string.action_delete, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        action(activity, comment, RedditAPI.ACTION_DELETE, changeDataManager);
                    }
                }).setNegativeButton(R.string.dialog_cancel, null).show();
        break;
    }

    case COMMENT_LINKS:
        final HashSet<String> linksInComment = comment.computeAllLinks();

        if (linksInComment.isEmpty()) {
            General.quickToast(activity, R.string.error_toast_no_urls_in_comment);

        } else {

            final String[] linksArr = linksInComment.toArray(new String[linksInComment.size()]);

            final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setItems(linksArr, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    LinkHandler.onLinkClicked(activity, linksArr[which], false);
                    dialog.dismiss();
                }
            });

            final AlertDialog alert = builder.create();
            alert.setTitle(R.string.action_comment_links);
            alert.setCanceledOnTouchOutside(true);
            alert.show();
        }

        break;

    case SHARE:

        final Intent mailer = new Intent(Intent.ACTION_SEND);
        mailer.setType("text/plain");
        mailer.putExtra(Intent.EXTRA_SUBJECT, "Comment by " + comment.author + " on Reddit");

        // TODO this currently just dumps the markdown
        mailer.putExtra(Intent.EXTRA_TEXT, StringEscapeUtils.unescapeHtml4(comment.body) + "\r\n\r\n"
                + comment.getContextUrl().generateNonJsonUri().toString());

        activity.startActivityForResult(Intent.createChooser(mailer, activity.getString(R.string.action_share)),
                1);

        break;

    case COPY_TEXT: {
        ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
        // TODO this currently just dumps the markdown
        manager.setText(StringEscapeUtils.unescapeHtml4(comment.body));
        break;
    }

    case COPY_URL: {
        ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
        // TODO this currently just dumps the markdown
        manager.setText(comment.getContextUrl().context(null).generateNonJsonUri().toString());
        break;
    }

    case COLLAPSE: {
        commentListingFragment.handleCommentVisibilityToggle(commentView);
        break;
    }

    case USER_PROFILE:
        LinkHandler.onLinkClicked(activity, new UserProfileURL(comment.author).toString());
        break;

    case PROPERTIES:
        CommentPropertiesDialog.newInstance(comment).show(activity.getSupportFragmentManager(), null);
        break;

    case GO_TO_COMMENT: {
        LinkHandler.onLinkClicked(activity, comment.getContextUrl().context(null).toString());
        break;
    }

    case CONTEXT: {
        LinkHandler.onLinkClicked(activity, comment.getContextUrl().toString());
        break;
    }
    case ACTION_MENU:
        showActionMenu(activity, commentListingFragment, renderableComment, commentView, changeDataManager,
                comment.isArchived());
        break;

    case BACK:
        activity.onBackPressed();
        break;
    }
}

From source file:com.game.simple.Game3.java

public static void openImage() {
    //---timer---//
    //StartReConnect();
    //-----------//
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.putExtra("return-data", true);
    self.startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_FILE);
}

From source file:org.geek.utils.ApplicationUtils.java

/**
 * Share a page./* w  w w . jav  a 2 s.  c  o  m*/
 * @param activity The parent activity.
 * @param title The page title.
 * @param url The page url.
 */
public static void sharePage(Activity activity, String title, String url) {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);

    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, url);
    shareIntent.putExtra(Intent.EXTRA_SUBJECT, title);

    try {
        activity.startActivity(
                Intent.createChooser(shareIntent, activity.getString(R.string.Main_ShareChooserTitle)));
    } catch (android.content.ActivityNotFoundException ex) {
        // if no app handles it, do nothing
    }
}

From source file:cn.ttyhuo.view.UserView.java

/**
 * //from  ww w.j a v a2s . c  o m
 * @param context 
 * @param activityTitle Activity??
 * @param msgTitle ?
 * @param msgText ?
 * @param imgPath ?null
 */
public static void shareMsg(Context context, String activityTitle, String msgTitle, String msgText, File f) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    if (f == null || !f.exists() || !f.isFile()) {
        intent.setType("text/plain"); // 
    } else {
        intent.setType("image/png");
        Uri u = Uri.fromFile(f);
        //Uri u = Uri.parse(imgPath);
        intent.putExtra(Intent.EXTRA_STREAM, u);
    }
    intent.putExtra(Intent.EXTRA_SUBJECT, msgTitle);
    intent.putExtra(Intent.EXTRA_TEXT, msgText);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(Intent.createChooser(intent, activityTitle));
}

From source file:com.game.simple.Game3.java

public static void sendEmail(String address, String subject, String content) {
    //---timer---//
    //StartReConnect();
    //-----------//
    String[] _address = { address.toString() };
    Intent email = new Intent(Intent.ACTION_SEND);
    email.putExtra(Intent.EXTRA_EMAIL, _address);
    email.putExtra(Intent.EXTRA_SUBJECT, subject);
    email.putExtra(Intent.EXTRA_TEXT, content);
    email.setType("message/rfc822");
    self.startActivity(Intent.createChooser(email, "Choose an Email client :"));

}

From source file:com.android.mms.ui.ConversationList.java

public static Intent createAddContactIntent(String address) {
    // address must be a single recipient
    Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
    intent.setType(Contacts.CONTENT_ITEM_TYPE);
    if (Mms.isEmailAddress(address)) {
        intent.putExtra(ContactsContract.Intents.Insert.EMAIL, address);
    } else {//ww w .ja v  a 2  s  .  com
        intent.putExtra(ContactsContract.Intents.Insert.PHONE, address);
        intent.putExtra(ContactsContract.Intents.Insert.PHONE_TYPE,
                ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE);
    }
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

    return intent;
}

From source file:com.googlecode.android_scripting.rpc.MethodDescriptor.java

public static Object buildIntent(JSONObject jsonObject) throws JSONException {
    Intent intent = new Intent();
    if (jsonObject.has("action")) {
        intent.setAction(jsonObject.getString("action"));
    }/* ww  w  .j  ava2s  .  c  om*/
    if (jsonObject.has("data") && jsonObject.has("type")) {
        intent.setDataAndType(Uri.parse(jsonObject.optString("data", null)),
                jsonObject.optString("type", null));
    } else if (jsonObject.has("data")) {
        intent.setData(Uri.parse(jsonObject.optString("data", null)));
    } else if (jsonObject.has("type")) {
        intent.setType(jsonObject.optString("type", null));
    }
    if (jsonObject.has("packagename") && jsonObject.has("classname")) {
        intent.setClassName(jsonObject.getString("packagename"), jsonObject.getString("classname"));
    }
    if (jsonObject.has("flags")) {
        intent.setFlags(jsonObject.getInt("flags"));
    }
    if (!jsonObject.isNull("extras")) {
        AndroidFacade.putExtrasFromJsonObject(jsonObject.getJSONObject("extras"), intent);
    }
    if (!jsonObject.isNull("categories")) {
        JSONArray categories = jsonObject.getJSONArray("categories");
        for (int i = 0; i < categories.length(); i++) {
            intent.addCategory(categories.getString(i));
        }
    }
    return intent;
}

From source file:com.contentecontent.cordova.plugins.share.Share.java

private void doSendIntent(String subject, String text, String imagePath, String mimeType) {
    Uri parsedUri = Uri.parse(imagePath);
    Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
    sendIntent.setType(mimeType);
    sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, text);
    sendIntent.putExtra(android.content.Intent.EXTRA_STREAM, parsedUri);
    this.cordova.startActivityForResult(this, sendIntent, 0);
}