파일 공유
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
앱에서 하나 이상의 파일을 다른 앱에 제공해야 하는 경우가 많습니다. 예를 들어 이미지 갤러리에서는 이미지 편집기에 파일을 제공하거나, 파일 관리 앱에서 사용자가 외부 저장소 영역 간에 파일을 복사하여 붙여넣을 수 있도록 허용하려고 할 수 있습니다. 전송 앱이 파일을 공유할 수 있는 한 가지 방법은 수신 앱의 요청에 응답하는 것입니다.
모든 경우에 앱에서 다른 앱으로 파일을 안전하게 제공하는 유일한 방법은 수신 앱에 파일의 콘텐츠 URI를 보내고 이 URI에 임시 액세스 권한을 부여하는 것입니다.
임시 URI 액세스 권한이 있는 콘텐츠 URI는 URI를 수신하는 앱에만 적용되고 자동으로 만료되므로 안전합니다. Android FileProvider
구성요소는 파일의 콘텐츠 URI를 생성하는 getUriForFile()
메서드를 제공합니다.
앱 간에 소량의 텍스트 또는 숫자 데이터를 공유하려면 데이터가 포함된 Intent
를 전송해야 합니다. Intent
를 사용하여 간단한 데이터를 보내는 방법을 알아보려면 간단한 데이터 공유 학습 과정을 참조하세요.
이 클래스에서는 Android FileProvider
구성요소에서 생성된 콘텐츠 URI 및 개발자가 콘텐츠 URI와 관련해 수신 앱에 부여하는 임시 권한을 사용하여 앱에서 다른 앱으로 파일을 안전하게 공유하는 방법을 설명합니다.
과정
- 파일 공유 설정
-
파일을 공유하도록 앱을 설정하는 방법을 알아보세요.
- 파일 공유
- 파일의 콘텐츠 URI를 생성하고 URI 액세스 권한을 부여하며 URI를 앱에 전송하여 다른 앱에 파일을 제공하는 방법을 알아봅니다.
- 공유 파일 요청
- 다른 앱에서 공유한 파일을 요청하고, 파일의 콘텐츠 URI를 수신하고, 콘텐츠 URI를 사용하여 파일을 여는 방법을 알아봅니다.
-
파일 정보 가져오기
- 앱이
FileProvider
에서 생성된 콘텐츠 URI를 사용하여 MIME 유형, 파일 크기 등 파일 정보를 검색하는 방법을 알아봅니다.
추가 관련 정보는 다음을 참조하세요.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[null,null,["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Sharing files\n\nApps often have a need to offer one or more of their files to another app. For example, an image\ngallery may want to offer files to image editors, or a file management app may want to allow\nusers to copy and paste files between areas in external storage. One way a sending app can\nshare a file is to respond to a request from the receiving app.\n\n\nIn all cases, the only secure way to offer a file from your app to another app is to send the\nreceiving app the file's content URI and grant temporary access permissions to that URI.\nContent URIs with temporary URI access permissions are secure because they apply only to the\napp that receives the URI, and they expire automatically. The Android\n[FileProvider](/reference/androidx/core/content/FileProvider) component provides the method\n[getUriForFile()](/reference/androidx/core/content/FileProvider#getUriForFile(android.content.Context, java.lang.String, java.io.File)) for\ngenerating a file's content URI.\n\n\nIf you want to share small amounts of text or numeric data between apps, you should send an\n[Intent](/reference/android/content/Intent) that contains the data. To learn how to send simple data with an\n[Intent](/reference/android/content/Intent), see the training class\n[Sharing simple data](/training/sharing).\n\n\nThis class explains how to securely share files from your app to another app using content URIs\ngenerated by the Android [FileProvider](/reference/androidx/core/content/FileProvider) component and\ntemporary permissions that you grant to the receiving app for the content URI.\n\nLessons\n-------\n\n**[Setting up file sharing](/training/secure-file-sharing/setup-sharing)**\n:\n Learn how to set up your app to share files.\n\n**[Sharing a file](/training/secure-file-sharing/share-file)**\n:\n Learn how to offer a file to another app by generating a content URI for the file,\n granting access permissions to the URI, and sending the URI to the app.\n\n**[Requesting a shared file](/training/secure-file-sharing/request-file)**\n:\n Learn how to request a file shared by another app, receive the content URI for the file,\n and use the content URI to open the file.\n\n\n**[Retrieving file information](/training/secure-file-sharing/retrieve-info)**\n:\n Learn how an app can use a content URI generated by a\n [FileProvider](/reference/androidx/core/content/FileProvider) to retrieve file information including\n MIME type and file size.\n\nFor additional related information, refer to:\n\n- [Storage Options](/guide/topics/data/data-storage)\n- [Saving Files](/training/basics/data-storage/files)\n- [Sharing Simple Data](/training/sharing)"]]