android - 使用 ACTION_SEND 打开共享对话框以共享文件

标签 android

我知道如何使用 ACTION_SEND 分享 A 文本。

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "Download Link https://play.google.com/store/apps/details?id=com.mtracker2051");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, "Share This App"));

我想使用 ShareDialog 共享一个文本文件。 我该怎么做。

我在这里读到这个http://developer.android.com/training/sharing/send.html但无法从此链接中获得太多信息。

最佳答案

String fileName = ...
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
emailIntent.setType("*/*");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {"Share File"}); 
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "File Name");   
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(fileName)));
startActivity(Intent.createChooser(emailIntent, "Share File"));

关于android - 使用 ACTION_SEND 打开共享对话框以共享文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16030711/

相关文章:

android - 谷歌端点使用带有本地 HTTP API 的资源管理器

android - IntentService 中的 NetworkOnMainThreadException

Android 亚马逊 s3 桶

android - NameValuePair 已弃用

android - 如何摆脱增量注释处理请求的警告?

android - 在 FrameLayout 中拉伸(stretch)图像以匹配相邻元素的高度?

android - 向后播放音频

android - 无法为 android 编译 vlc

android:实现经纬度

Android ListActivity - 固定页眉和页脚