2013-04-16 110 views
1

我知道如何使用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沒有從這個鏈接得到很多。

+0

我認爲你所說的ShareDialog實際上是一個Intent選擇器,並且你已經在你的代碼中使用它。 – Egor

+0

是的,但我想分享一個文本文件。 – kamal

+0

這是什麼問題? – Egor

回答

6
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