Android的份额文件:我知道什么时候该文件已被共享或选择器被取消? [英] Android share file: can I know when the file has been shared or the chooser was cancelled?

查看:66
本文介绍了Android的份额文件:我知道什么时候该文件已被共享或选择器被取消?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个共享选项的应用程序。当它在用户点击时,文件创建,然后一个选择器显示要求用户进行共享他怎么想分享(邮件,Skype和谷歌驱动器...)。一旦文件被共享或选配取消我要删除的文件,因为它不再需要。

I have an application with a Share option. When the user clicks on it, a file to be shared is created and then a chooser is shown to ask the user how does he want to share it (mail, skype, google drive...). Once the file has been shared or the chooser is cancelled I want to delete the file since it's no longer needed.

我想要的文件名具有当前的日期,因此,覆盖在同一文件中的每个时间不是一个选项。有没有什么办法知道什么时候是不是需要这个文件了?

I want the filename to have the current date, so overriding the same file each time is not an option. Is there any way to know when this file isn't needed anymore??

要分享我用这个code中的文件:

To share the file I use this code:

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/csv");
sharingIntent.putExtra(Intent.EXTRA_STREAM, csv);
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
startActivity(Intent.createChooser(sharingIntent, getResources().getText(R.string.send_to)));

谢谢!

推荐答案

而不是 startActivity ,选择器需要使用启动 startActivityForResult 。或选配没有关闭,直到它的取消文件是共享的,因此该文件可以在的onActivityResult 被删除。

Instead of startActivity, the chooser needs to be started using startActivityForResult. The chooser isn't closed until it's cancelled or the file is shared, so the file can be deleted in onActivityResult.

这篇关于Android的份额文件:我知道什么时候该文件已被共享或选择器被取消?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆