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

时间:2013-04-16 07:01:31

标签: android

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

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,但是从这个链接中得不到多少。

1 个答案:

答案 0 :(得分:7)

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"));