亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在Android中發送帶有文件附件的電子郵件

如何在Android中發送帶有文件附件的電子郵件

嗶嗶one 2019-11-14 09:16:10
我想在郵件中附加.vcf文件并通過郵件發送。但是郵件是在沒有附件的地址上收到的。我已經使用了下面的代碼,但是代碼并不知道我錯了。try {        String filelocation="/mnt/sdcard/contacts_sid.vcf";        Intent intent = new Intent(Intent.ACTION_SENDTO);      intent.setType("text/plain");        intent.putExtra(Intent.EXTRA_SUBJECT, "");        intent.putExtra(Intent.EXTRA_STREAM, Uri.parse( "file://"+filelocation));        intent.putExtra(Intent.EXTRA_TEXT, message);           intent.setData(Uri.parse("mailto:"));           intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);   activity.startActivity(intent);  activity.finish();  } catch(Exception e)  {     System.out.println("is exception raises during sending mail"+e);}
查看完整描述

3 回答

?
慕森王

TA貢獻1777條經驗 獲得超3個贊

Folder_name是手機內部存儲器中文件的名稱。(實際上是EXTERNAL_STORAGE)。file_name是您要發送的文件的名稱。


private void ShareViaEmail(String folder_name, String file_name) {

    try {

        File root= Environment.getExternalStorageDirectory();

        String filelocation= root.getAbsolutePath() + folder_name + "/" + file_name;

        Intent intent = new Intent(Intent.ACTION_SENDTO);

        intent.setType("text/plain");

        String message="File to be shared is " + file_name + ".";

        intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");

        intent.putExtra(Intent.EXTRA_STREAM, Uri.parse( "file://"+filelocation));

        intent.putExtra(Intent.EXTRA_TEXT, message);

        intent.setData(Uri.parse("mailto:[email protected]"));

        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);


        startActivity(intent);

    } catch(Exception e)  {

        System.out.println("is exception raises during sending mail"+e);

    }

}


查看完整回答
反對 回復 2019-11-14
?
12345678_0001

TA貢獻1802條經驗 獲得超5個贊

使用以下代碼在電子郵件中發送文件。


String filename="contacts_sid.vcf"; 

File filelocation = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), filename);

Uri path = Uri.fromFile(filelocation); 

Intent emailIntent = new Intent(Intent.ACTION_SEND);

// set the type to 'email'

emailIntent .setType("vnd.android.cursor.dir/email");

String to[] = {"[email protected]"};

emailIntent .putExtra(Intent.EXTRA_EMAIL, to);

// the attachment

emailIntent .putExtra(Intent.EXTRA_STREAM, path);

// the mail subject

emailIntent .putExtra(Intent.EXTRA_SUBJECT, "Subject");

startActivity(Intent.createChooser(emailIntent , "Send email..."));


查看完整回答
反對 回復 2019-11-14
  • 3 回答
  • 0 關注
  • 745 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號