Android sharing Files, by sending them via email o

2020-02-07 18:51发布

I have a list of files in my android app and I want to be able to get the selected items and send them via email or any other sharing app. Here is my code.

Intent sendIntent = new Intent();
                    sendIntent.setAction(Intent.ACTION_SEND);
                    sendIntent.putExtra(Intent.EXTRA_EMAIL, getListView().getCheckedItemIds());
                    sendIntent.setType("text/plain");
                    startActivity(sendIntent);

8条回答
smile是对你的礼貌
2楼-- · 2020-02-07 19:54

Use ACTION_SEND_MULTIPLE for delivering multiple data to someone

intent.setAction(Intent.ACTION_SEND_MULTIPLE);
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, arrayUri);
intent.setType("text/plain");
startActivity(intent);

The arrayUri is the Array List of Uri of files to Send.

查看更多
神经病院院长
3楼-- · 2020-02-07 19:56

Here is an example to share or save a text file:

private void shareFile(String filePath) {

    File f = new File(filePath);

    Intent intentShareFile = new Intent(Intent.ACTION_SEND);
    File fileWithinMyDir = new File(filePath);

    if (fileWithinMyDir.exists()) {
        intentShareFile.setType("text/*");
        intentShareFile.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + filePath));
        intentShareFile.putExtra(Intent.EXTRA_SUBJECT, "MyApp File Share: " + f.getName());
        intentShareFile.putExtra(Intent.EXTRA_TEXT, "MyApp File Share: " + f.getName());

        this.startActivity(Intent.createChooser(intentShareFile, f.getName()));
    }
}
查看更多
登录 后发表回答