android.content.Intent#ACTION_SEND源码实例Demo

下面列出了android.content.Intent#ACTION_SEND 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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);
}
 
源代码2 项目: JianDan   文件: ShareUtil.java
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)));
    }
 
源代码3 项目: androiddevice.info   文件: Application.java
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);
    }

}
 
源代码4 项目: Android-Commons   文件: Social.java
/**
 * 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));
}
 
源代码5 项目: IPTVFree   文件: BugReport.java
/**
 * 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();
    }
}
 
源代码6 项目: FriendBook   文件: Shares.java
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)));
}
 
源代码7 项目: CloudReader   文件: ShareUtils.java
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)));
}
 
源代码8 项目: android-discourse   文件: TopicFragment.java
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);

}
 
源代码9 项目: XKnife-Android   文件: IntentUtils.java
/**
 * 获取分享图片的意图
 *
 * @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);
}
 
源代码10 项目: iBeebo   文件: Utility.java
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);
    }

}
 
源代码11 项目: HeadFirstAndroid   文件: PizzaDetailActivity.java
@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;
}
 
源代码12 项目: SmsCode   文件: BackupManager.java
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));
}
 
源代码13 项目: geopaparazzi   文件: ShareUtilities.java
/**
 * 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));
}
 
源代码14 项目: playa   文件: BrowserActivity.java
@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);
}
 
源代码15 项目: android-project-wo2b   文件: AboutActivity.java
/**
 * 分享给好友
 * 
 * @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()));
}
 
源代码16 项目: MarkdownEditors   文件: EditorFragment.java
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();
    }
 
源代码17 项目: Conversations   文件: EditAccountActivity.java
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)));
}
 
@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;
}
 
源代码19 项目: sdk3rd   文件: SendShare.java
@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;
        }
    }
 
源代码20 项目: geopaparazzi   文件: ShareUtilities.java
/**
 * 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));
}
 
 方法所在类
 同类方法