Google Android开发者文档系列-创建有内容分享特性的应用之文件共享(序言)

来源:互联网 发布:淘宝制作假订单生成器 编辑:程序博客网 时间:2024/05/29 15:28

Sharing Files(文件共享)

该系列文章是我在学习Google开发者文档时结合谷歌翻译和自身理解编写的,希望对学习Android开发的朋友带来些便利,由于个人翻译水平有限,所以内容包含原文和译文,希望浏览者结合理解,以免步入我可能错译的误区。在此感谢http://android.xsoftlab.net/提供的镜像,希望转载者注明出处http://blog.csdn.net/u014031072/article/details/51595080方便查看最新博客

Apps often have a need to offer one or more of their files to another app. For example, an image gallery may want to offer files to image editors, or a file management app may want to allow users to copy and paste files between areas in external storage. One way a sending app can share a file is to respond to a request from the receiving app.
应用程序往往需要提供一个或更多的文件到另一个应用程序。例如,一个图片库可能要提供文件给图像编辑器或可能允许用户在外部存储区域之间复制和粘贴文件的文件管理应用程序。发送app共享文件的一种方法是对接收app的一个请求作出响应。

In all cases, the only secure way to offer a file from your app to another app is to send the receiving app the file’s content URI and grant temporary access permissions to that URI. Content URIs with temporary URI access permissions are secure because they apply only to the app that receives the URI, and they expire automatically. The Android FileProvider component provides the method getUriForFile() for generating a file’s content URI.
任何情况下,当从你的app为另一个app提供一个文件时,唯一安全的方式是像接收app发送文件的content URI和该URI的临时进入许可。拥有临时进入许可的content URI是安全的,因为它们只适用于接收URI的app,而且它们会自动失效。Android FileProvider组件提供了getUriForFile()方法来生成一个文件的content URI。

If you want to share small amounts of text or numeric data between apps, you should send an Intent that contains the data. To learn how to send simple data with an Intent, see the training class Sharing Simple Data.
如果你想在app间共享少量文本或者数字数据,你应该发送一个包含该数据的intent。学习如何通过intent发送简单数据,查看《Google Android开发者文档系列-创建有内容分享特性的应用之发送简单数据到其它应用程序》系列文章。

This class explains how to securely share files from your app to another app using content URIs generated by the Android FileProvider component and temporary permissions that you grant to the receiving app for the content URI.
本课程将介绍如何通过Android FileProvider 生成的content URI和该content URI的临时授权文件实现你的app与其他app间的的文件安全共享。

Lessons(课程)

Setting Up File Sharing(设置文件共享)
Learn how to set up your app to share files.
学习如何为你的app设置文件共享

Sharing a File(共享文件)
Learn how to offer a file to another app by generating a content URI for the file, granting access permissions to the URI, and sending the URI to the app.
学习如何通过产生一个content URI、授予该URI临时进入权限、发送该URI到对应app,来实现为另一个app提供共享文件

Requesting a Shared File(请求共享文件)
Learn how to request a file shared by another app, receive the content URI for the file, and use the content URI to open the file.
学习如何请求另一个app共享的文件、获取对应文件的content URI、使用content URI打开对应文件。

Retrieving File Information(获取文件信息)
Learn how an app can use a content URI generated by a FileProvider to retrieve file information including MIME type and file size.
学习如何通过FileProvider生成的content URI来获取文件信息包括MIME类型和文件大小。

0 0
原创粉丝点击