How to share *.txt file in android

主宰稳场 提交于 2019-12-04 08:29:31

Change your Code Like this.

From

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

To

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

from:

sharingIntent.setType("*/txt");

To

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"));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!