ACTION_SEND-共享文件名与光盘上的文件名不同的文件 [英] ACTION_SEND - Share File with Different Filename Than That on Disc

查看:71
本文介绍了ACTION_SEND-共享文件名与光盘上的文件名不同的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题的简短版本.

是否可以启动ACTION_SEND意图以共享磁盘上的文件,但共享使用的文件名与磁盘上的文件名不同?

Is it possible to launch a ACTION_SEND intent in order to share a file on disc but to have a different filename used by the share than the filename on disc?

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/png");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile("somepath/3c72ae1adacb.dat"));
// BEGIN Hopefully something like this exists....
shareIntent.putExtra(Intent.EXTRA_FILENAME, "CuteKittens.png"));
// END
startActivity(shareIntent);

长版...

出于安全原因,我的Android应用程序中使用的某些文件在光盘上的文件名变得模糊不清,例如"3c72ae1adacb.dat".

For security reasons some of the files used within my Android app have obscured filenames on disc such as "3c72ae1adacb.dat".

我希望已登录的用户能够共享这些文件,但使用其文件名(例如"CuteKittens.png")保持一致.

I would like for logged in users to be able to share these files but with their un-obscured filename such as "CuteKittens.png".

这可以实现吗? (理想情况下,无需将文件复制到磁盘上,而是共享副本并最终将其删除,这样做似乎很费事,所以很简单).

Is this achievable? (Ideally without copying the file on disc, sharing the copy and finally deleting it which seems like a lot of work for something so straight forward).

推荐答案

通常不应该使用file:// Uri值,因为不能保证其他应用程序可以读取这些文件.

You should not be using file:// Uri values in general, as there is no guarantee that other apps can read those files.

欢迎您实现为这些文件提供服务的ContentProvider,其中Uri值具有未模糊的文件名".因此,而不是:

You are welcome to implement a ContentProvider that serves up these files, where your Uri values have the "un-obscured filename". So, rather than:

shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile("somepath/3c72ae1adacb.dat"));

您将拥有:

shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("content://your.authority.goes.here/files/CuteKittens.png"));

ContentProvider会通过一种或另一种方式知道CuteKittens.png的内容是在somepath/3c72ae1adacb.dat中找到的.

and the ContentProvider would know, by one means or another, that the content for CuteKittens.png is found in somepath/3c72ae1adacb.dat.

几乎所有您都需要内置的FileProvider,只是我假设在编译时不知道文件名(原始文件名和重命名文件).

The built-in FileProvider is almost what you need, except that I assume that the filenames (both original and renamed) are not known at compile time.

这篇关于ACTION_SEND-共享文件名与光盘上的文件名不同的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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