Oli*_*ain 8 android share android-intent
问题的简短版本
是否可以启动ACTION_SEND意图以共享光盘上的文件,但共享使用的文件名不同于光盘上的文件名?
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);
Run Code Online (Sandbox Code Playgroud)
长版......
出于安全考虑,我的Android应用程序中使用的某些文件掩盖了光盘上的文件名,例如"3c72ae1adacb.dat".
我希望登录的用户能够共享这些文件,但文件名不明确,如"CuteKittens.png".
这可以实现吗?(理想情况下,不要在光盘上复制文件,共享副本并最终删除它,这对于如此直接的事情似乎很多工作).
一般来说,您不应该使用file:// Uri值,因为不能保证其他应用程序可以读取这些文件。
欢迎您实现ContentProvider提供这些文件的服务,其中您的Uri值具有“不模糊的文件名”。所以,而不是:
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile("somepath/3c72ae1adacb.dat"));
Run Code Online (Sandbox Code Playgroud)
你将会拥有:
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("content://your.authority.goes.here/files/CuteKittens.png"));
Run Code Online (Sandbox Code Playgroud)
并且ContentProvider会通过某种方式知道 的内容CuteKittens.png位于 中somepath/3c72ae1adacb.dat。
内置的FileProvider几乎是你所需要的,除了我假设文件名(原始的和重命名的)在编译时是未知的。
| 归档时间: |
|
| 查看次数: |
1396 次 |
| 最近记录: |