且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Android***享* .txt文件

更新时间:2023-02-01 17:28:49

像这样更改代码。

发件人

File file = new File(Environment.getExternalStorageDirectory(), "Email-Ghap/Emails.txt");

File file = new File(Environment.getExternalStorageDirectory() + "/" + "Email-Ghap/Emails.txt");

来自:

sharingIntent.setType("*/txt");

sharingIntent.setType("text/*");

所以您的最终代码看起来像

so yourFinal Code Looks Like

    File file = new File(Environment.getExternalStorageDirectory().toString() + "/" + "abc.txt");
            Intent sharingIntent = new Intent(Intent.ACTION_SEND);
            sharingIntent.setType("text/*");
            sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file.getAbsolutePath()));
            startActivity(Intent.createChooser(sharingIntent, "share file with"));