天天看點

android 郵箱分享(添加附件篩選郵箱應用)

/**
     * 發送郵件
     *
     * @param title
     * @param email
     * @param extraText
     */
    public static void sendEmail(String title, String[] email, String extraText) {
        if (ArrayUtils.isEmpty(email)) {
            return;
        }
        Intent emailTartget = new Intent(android.content.Intent.ACTION_SEND);
        /*不帶附件發送郵件*/
        emailTartget.setType("plain/text");

        /*設定郵件預設位址,多個收件人,String數組*/
        emailTartget.putExtra(android.content.Intent.EXTRA_EMAIL, email);
//        emailTartget.putExtra(android.content.Intent.EXTRA_EMAIL, (String[])mMailReceivers.toArray(new String[mMailReceivers.size()]));
        /*多個抄送人,String數組*/
//        emailTartget.putExtra(android.content.Intent.EXTRA_CC, (String[])mMailCopyTos.toArray(new String[mMailCopyTos.size()]));
        /*郵件标題*/
        emailTartget.putExtra(android.content.Intent.EXTRA_SUBJECT, "Android-" + SystemUtil.getSystemModel() + "-" + SystemUtil.getSystemVersion());
        /*郵件正文*/
        emailTartget.putExtra(android.content.Intent.EXTRA_TEXT, extraText);
        //調用系統的郵件系統
        ActivityUtils.startActivity(Intent.createChooser(emailTartget, title));
    }

    /**
     * 郵件分享壓縮檔案
     *
     * @param file
     * @param title
     */
    public static void sendZipFileEmial(Context context, File file, String title, String... email) {

        Intent emailSelectorIntent = new Intent(Intent.ACTION_SENDTO);
        emailSelectorIntent.setData(Uri.parse("mailto:"));

        final Intent emailIntent = new Intent(Intent.ACTION_SEND);
        emailIntent.putExtra(Intent.EXTRA_TITLE, title);
        emailIntent.putExtra(Intent.EXTRA_EMAIL, email);
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, AppUtils.getAppName() + "(Android)");
        emailIntent.putExtra(Intent.EXTRA_TEXT, "");
        emailIntent.setSelector(emailSelectorIntent);
        if (file != null) {
            // 添加附件
            Uri uri = Uri.fromFile(file);
            emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
        }
        if (emailIntent.resolveActivity(context.getPackageManager()) != null) {
            ActivityUtils.startActivity(emailIntent);
        }
    }