Sharing a text file with ACTION_SEND

We can open the sharing dialog using ACTION_SEND to exchange text

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

How can I use ACTION_SEND to share a text file.

I read http://developer.android.com/training/sharing/send.html but could not get a way to share a text file.

+6
source share
1 answer

Use the following line.

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

Make sure that the path to the text file must be from an external memory card. The send action does not accept files from internal memory.

Hope this helps you.

+9
source