微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 使用ACTION_SEND共享文本文件

我们可以使用ACTION_SEND打开共享对话框来共享文本
Intent sendIntent = new Intent();
                sendIntent.setAction(Intent.ACTION_SEND);
                sendIntent.putExtra(Intent.EXTRA_TEXT,"Download Link: Android play store link");
                sendIntent.setType("text/plain");
                startActivity(Intent.createChooser(sendIntent,"Share This App"));

如何使用ACTION_SEND共享文本文件.

我读了http://developer.android.com/training/sharing/send.html,但无法获得如何共享文本文件.

解决方法

使用以下行.
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
    emailIntent.setType("*/*");
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] {"me@gmail.com"}); 
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Test Subject"); 
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"go on read the emails");     
    emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromfile(new File(yourtextfilepath));
    startActivity(Intent.createChooser(emailIntent,"Send mail..."));

确保文本文件路径应来自外部存储卡.动作发送不接受内部存储器中的文件.

希望这会帮助你.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐