打开共享对话框以共享文件使用ACTION_SEND
问题描述:
我知道如何使用ACTION_SEND共享文本。打开共享对话框以共享文件使用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但cound没有从这个链接得到很多。
答
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"));
+0
共享文件URI不会在不同的配置文件中工作。 http://developer.android.com/training/enterprise/app-compatibility.html#sharing_files – rds
我认为你所说的ShareDialog实际上是一个Intent选择器,并且你已经在你的代码中使用它。 – Egor
是的,但我想分享一个文本文件。 – kamal
这是什么问题? – Egor