Java Code Examples for android.content.Intent#ACTION_SEND

The following examples show how to use android.content.Intent#ACTION_SEND . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
final void sendEmail(String[] to,
                     String[] cc,
                     String[] bcc,
                     String subject,
                     String body) {
  Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));
  if (to != null && to.length != 0) {
    intent.putExtra(Intent.EXTRA_EMAIL, to);
  }
  if (cc != null && cc.length != 0) {
    intent.putExtra(Intent.EXTRA_CC, cc);
  }
  if (bcc != null && bcc.length != 0) {
    intent.putExtra(Intent.EXTRA_BCC, bcc);
  }
  putExtra(intent, Intent.EXTRA_SUBJECT, subject);
  putExtra(intent, Intent.EXTRA_TEXT, body);
  intent.setType("text/plain");
  launchIntent(intent);
}
 
Example 2
Source Project: JianDan   File: ShareUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static void sharePicture(Activity activity, String imgPath, String shareText) {

        Intent intent = new Intent(Intent.ACTION_SEND);
        File f = new File(imgPath);
        if (f != null && f.exists() && f.isFile()) {
            intent.setType("image/*");
            intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
        } else {
            ShowToast.Short("分享图片不存在哦");
            return;
        }

        //GIF图片指明出处url,其他图片指向项目地址
        if (imgPath.endsWith(".gif")) {
            intent.putExtra(Intent.EXTRA_TEXT, shareText);
        }

        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        activity.startActivity(Intent.createChooser(intent, activity.getResources().getString(R
                .string.app_name)));
    }
 
Example 3
private void handleUncaughtException (Thread thread, Throwable t)
{
    try {
        android.content.pm.PackageInfo packageinfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);

        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("plain/text");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{context.getString(R.string.email)});
        intent.putExtra(android.content.Intent.EXTRA_SUBJECT, context.getString(R.string.subject));
        intent.putExtra(android.content.Intent.EXTRA_TEXT, new Error(packageinfo, t).toString());

        Intent mail = Intent.createChooser(intent, context.getString(R.string.crashtitle));
        mail.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(mail);
    } catch(Exception e) {
    } finally {
        Runtime.getRuntime().exit(0);
    }

}
 
Example 4
Source Project: Android-Commons   File: Social.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Displays an application chooser and shares the specified plain text and subject line using the selected application
 *
 * @param context a context reference
 * @param windowTitle the title for the application chooser's window
 * @param bodyTextToShare the body text to be shared
 * @param subjectTextToShare the title or subject for the message to be shared, if supported by the target application
 */
public static void shareText(final Context context, final String windowTitle, final String bodyTextToShare, final String subjectTextToShare) {
	final Intent intentInvite = new Intent(Intent.ACTION_SEND);
	intentInvite.setType(HTTP.PLAIN_TEXT_TYPE);
	intentInvite.putExtra(Intent.EXTRA_SUBJECT, subjectTextToShare);
	intentInvite.putExtra(Intent.EXTRA_TEXT, bodyTextToShare);

	context.startActivity(Intent.createChooser(intentInvite, windowTitle));
}
 
Example 5
Source Project: IPTVFree   File: BugReport.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This method initialize an itent to send an email to developers.
 * @param activity Activity
 */
public static void reportBug(Activity activity)
{
    Intent i = new Intent(Intent.ACTION_SEND);
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.setType("message/rfc822");
    i.putExtra(Intent.EXTRA_EMAIL, new String[]{activity.getResources().getString(R.string.email)});
    i.putExtra(Intent.EXTRA_SUBJECT, activity.getResources().getString(R.string.email_subject_bug));
    i.putExtra(Intent.EXTRA_TEXT, Utils.getSystemInformation() + "\n" + activity.getResources().getString(R.string.email_text_bug));
    try {
        activity.startActivity(Intent.createChooser(i, activity.getResources().getString(R.string.email_send)));
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(activity, activity.getResources().getString(R.string.email_failed), Toast.LENGTH_SHORT).show();
    }
}
 
Example 6
Source Project: FriendBook   File: Shares.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void share(Context context, String extraText) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.share));
    intent.putExtra(Intent.EXTRA_TEXT, extraText);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(
            Intent.createChooser(intent, context.getString(R.string.share)));
}
 
Example 7
Source Project: CloudReader   File: ShareUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void share(Context context, String extraText) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.action_share));
    intent.putExtra(Intent.EXTRA_TEXT, extraText);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(
            Intent.createChooser(intent, context.getString(R.string.action_share)));
}
 
Example 8
Source Project: android-discourse   File: TopicFragment.java    License: Apache License 2.0 5 votes vote down vote up
protected void onShareClicked(View v) {
    int position = getPositionForView(v);
    // Post post = (Post) mAdapter.getItem(position);
    String url = null;
    if (App.isLogin()) {
        url = String.format(Api.SHARE_LOGIN, mSlug, mId, position + 1, App.getUsername());
    } else {
        url = String.format(Api.SHARE, mSlug, mId, position + 1);
    }
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_TEXT, mSiteUrl + url);
    intent.setType("text/plain");
    startActivity(intent);

}
 
Example 9
Source Project: XKnife-Android   File: IntentUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 获取分享图片的意图
 *
 * @param content 分享文本
 * @param uri     图片uri
 * @return intent share image intent
 */
public static Intent getShareImageIntent(String content, Uri uri) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_TEXT, content);
    intent.putExtra(Intent.EXTRA_STREAM, uri);
    intent.setType("image/*");
    return intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
 
Example 10
Source Project: iBeebo   File: Utility.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void setShareIntent(Activity activity, ShareActionProvider mShareActionProvider, String content) {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, content);
    if (Utility.isIntentSafe(activity, shareIntent) && mShareActionProvider != null) {
        mShareActionProvider.setShareIntent(shareIntent);
    }

}
 
Example 11
Source Project: HeadFirstAndroid   File: PizzaDetailActivity.java    License: MIT License 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);

    //Share the name of the pizza
    TextView textView = (TextView)findViewById(R.id.pizza_text);
    CharSequence pizzaName = textView.getText();
    MenuItem menuItem = menu.findItem(R.id.action_share);
    shareActionProvider = (ShareActionProvider) menuItem.getActionProvider();
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, pizzaName);
    shareActionProvider.setShareIntent(intent);
    return true;
}
 
Example 12
public static void shareBackupFile(Context context, File file) {
    Intent intent = new Intent(Intent.ACTION_SEND);

    Uri uri = FileProvider.getUriForFile(context, BACKUP_FILE_AUTHORITY, file);
    intent.putExtra(Intent.EXTRA_STREAM, uri);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    intent.setType(BACKUP_MIME_TYPE);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    context.startActivity(Intent.createChooser(intent, null));
}
 
Example 13
/**
 * Share text and image.
 *
 * @param context      the context to use.
 * @param titleMessage title.
 * @param textToShare  text.
 * @param imageFile    the image file.
 */
public static void shareTextAndImage(Context context, String titleMessage, String textToShare, File imageFile) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, textToShare);
    Uri uri = Uri.fromFile(imageFile);
    intent.putExtra(Intent.EXTRA_STREAM, uri);
    context.startActivity(Intent.createChooser(intent, titleMessage));
}
 
Example 14
Source Project: playa   File: BrowserActivity.java    License: MIT License 5 votes vote down vote up
@Override
public void openShareDialog() {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    String dialogTitle = getString(R.string.share_dialog_title);
    String shareContent = "【" + title + "】:" + url
            + " (" + getString(R.string.share_source) + ")";
    intent.putExtra(Intent.EXTRA_SUBJECT, dialogTitle);
    intent.putExtra(Intent.EXTRA_TEXT, shareContent);
    startActivity(intent);
}
 
Example 15
/**
 * 分享给好友
 * 
 * @param v
 */
private void onShareToFriends(View v)
{
	Intent intent = new Intent(Intent.ACTION_SEND);
	// intent.setType("image/*");
	intent.setType("text/plain");
	intent.putExtra(Intent.EXTRA_SUBJECT, "应用分享");
	intent.putExtra(Intent.EXTRA_TEXT, "亲,分享一款用心的应用『图界传说』。下载地址:http://www.wo2b.com");
	intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	startActivity(Intent.createChooser(intent, getTitle()));
}
 
Example 16
Source Project: MarkdownEditors   File: EditorFragment.java    License: Apache License 2.0 5 votes vote down vote up
private void shareMD() {
        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(mPresenter.getMDFile()));
        shareIntent.setType("*/*");

//        startActivity(Intent.createChooser(share,"Share Image"));
        BottomSheet.Builder builder = new BottomSheet.Builder(getActivity());
        builder.setIntent(getActivity(), shareIntent);
        BottomSheet bottomSheet = builder.create();
        bottomSheet.show();
    }
 
Example 17
private void shareBarcode() {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_STREAM, BarcodeProvider.getUriForAccount(this, mAccount));
    intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    intent.setType("image/png");
    startActivity(Intent.createChooser(intent, getText(R.string.share_with)));
}
 
Example 18
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            finish();
            return true;
        case R.id.action_sort_view_subreddit_detail_activity:
            sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag());
            return true;
        case R.id.action_search_view_subreddit_detail_activity:
            Intent intent = new Intent(this, SearchActivity.class);
            intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, subredditName);
            startActivity(intent);
            return true;
        case R.id.action_refresh_view_subreddit_detail_activity:
            if (mMenu != null) {
                mMenu.findItem(R.id.action_lazy_mode_view_subreddit_detail_activity).setTitle(R.string.action_start_lazy_mode);
            }
            sectionsPagerAdapter.refresh();
            mFetchSubredditInfoSuccess = false;
            fetchSubredditData();
            return true;
        case R.id.action_lazy_mode_view_subreddit_detail_activity:
            if (sectionsPagerAdapter != null) {
                MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_view_subreddit_detail_activity);
                if (isInLazyMode) {
                    isInLazyMode = false;
                    sectionsPagerAdapter.stopLazyMode();
                    lazyModeItem.setTitle(R.string.action_start_lazy_mode);
                    params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS |
                            AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED);
                    collapsingToolbarLayout.setLayoutParams(params);
                } else {
                    isInLazyMode = true;
                    if (sectionsPagerAdapter.startLazyMode()) {
                        lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
                        appBarLayout.setExpanded(false);
                        params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED);
                        collapsingToolbarLayout.setLayoutParams(params);
                    } else {
                        isInLazyMode = false;
                    }
                }
            }
            return true;
        case R.id.action_change_post_layout_view_subreddit_detail_activity:
            postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
            return true;
        case R.id.action_share_view_subreddit_detail_activity:
            Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.setType("text/plain");
            shareIntent.putExtra(Intent.EXTRA_TEXT, "https://www.reddit.com/r/" + subredditName);
            if (shareIntent.resolveActivity(getPackageManager()) != null) {
                startActivity(Intent.createChooser(shareIntent, getString(R.string.share)));
            } else {
                Toast.makeText(this, R.string.no_app, Toast.LENGTH_SHORT).show();
            }
            return true;
    }
    return false;
}
 
Example 19
Source Project: sdk3rd   File: SendShare.java    License: Apache License 2.0 4 votes vote down vote up
@Override
    public void share(@NonNull final ShareData data, @NonNull final OnCallback<String> callback) {

        if (mPlatform.getName().equals(ShareTo.ToQQ)) {
            if (!isApplicationInstalled(mActivity, PACKAGE_QQ)) {
                callback.onFailed(mActivity, ResultCode.RESULT_FAILED, "无法分享,请先安装QQ");
                return;
            }
        } else {
            if (!isApplicationInstalled(mActivity, PACKAGE_WX)) {
                callback.onFailed(mActivity, ResultCode.RESULT_FAILED, "无法分享,请先安装微信");
                return;
            }
        }
        Intent intent = new Intent(Intent.ACTION_SEND);

        if (mPlatform.getName().equals(ShareTo.ToQQ)) {
            intent.setClassName(PACKAGE_QQ, "com.tencent.mobileqq.activity.JumpActivity");
        } else if (mPlatform.getName().equals(ShareTo.ToWXSession)) {
            intent.setClassName(PACKAGE_WX, "com.tencent.mm.ui.tools.ShareImgUI");
        } else {
            intent.setClassName(PACKAGE_WX, "com.tencent.mm.ui.tools.ShareToTimeLineUI");
        }

        switch (data.type()) {
        case IMediaObject.TYPE_IMAGE:
            intent.setType("image/*");
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION);



            ImageResource resource = ((MoImage) data.media).resource;
            if (resource instanceof BitmapResource) {
                final Uri uri = Uri.parse(MediaStore.Images.Media.insertImage(mActivity.getContentResolver(), resource.toBitmap(), null, null));
                intent.putExtra(Intent.EXTRA_STREAM, uri);
            } else if (resource instanceof FileResource) {
                intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(((FileResource) resource).file));
            } else {
                Log.e("ezy", "" + Uri.parse(resource.toUri()));
                intent.setData(Uri.parse(resource.toUri()));
//                final Uri uri = Uri.parse(MediaStore.Images.Media.insertImage(mActivity.getContentResolver(), data.thumb.toBitmap(), null, null));
//                intent.putExtra(Intent.EXTRA_STREAM, uri);
            }
            break;
        case IMediaObject.TYPE_TEXT:
            intent.setType("text/plain");
            intent.putExtra("Kdescription", data.text);
            intent.putExtra(Intent.EXTRA_TEXT, data.text);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            break;
        default:
            callback.onFailed(mActivity, ResultCode.RESULT_FAILED, "不支持的分享类型");
            return;
        }
        if (isIntentAvailable(mActivity, intent)) {
            mActivity.startActivity(intent);
        } else {
            callback.onFailed(mActivity, ResultCode.RESULT_FAILED, "分享失败");
            return;
        }
    }
 
Example 20
/**
 * Share text.
 *
 * @param context      the context to use.
 * @param titleMessage title.
 * @param textToShare  text.
 */
public static void shareText(Context context, String titleMessage, String textToShare) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, textToShare);
    context.startActivity(Intent.createChooser(intent, titleMessage));
}