콘텐츠 제공자
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
콘텐츠 제공자는 애플리케이션이 단독으로 저장되었거나 다른 앱에 의해 저장된 데이터에 대한 액세스를 관리하도록 돕고 다른 앱과 데이터를 공유하는 방법을 제공할 수 있습니다. 데이터를 캡슐화하고 데이터 보안을 정의하는 메커니즘을 제공합니다. 콘텐츠 제공자는 한 프로세스의 데이터를 다른 프로세스에서 실행 중인 코드와 연결하는 표준 인터페이스입니다.
콘텐츠 제공자를 구현하면 많은 장점을 누릴 수 있습니다. 가장 중요한 점은 그림 1과 같이 다른 애플리케이션에서 앱 데이터에 안전하게 액세스하고 수정할 수 있도록 콘텐츠 제공자를 구성할 수 있다는 것입니다.
그림 1. 콘텐츠 제공자가 저장소에 대한 액세스를 관리하는 방법의 개요 다이어그램
데이터를 공유할 계획이라면 콘텐츠 제공자를 사용하세요. 데이터를 공유할 계획이 없다면 사용하지 않아도 되지만 데이터 액세스에 의존하는 다른 애플리케이션에 영향을 주지 않고 애플리케이션 데이터 스토리지 구현을 수정할 수 있는 추상화를 제공하기 때문에 데이터를 공유할 수 있습니다.
이 시나리오에서는 콘텐츠 제공자만 영향을 받고 여기에 액세스하는 애플리케이션은 영향을 받지 않습니다. 예를 들어, SQLite 데이터베이스를 대체 저장소로 교체할 수 있습니다(그림 2 참고).
그림 2. 콘텐츠 제공자 저장소를 마이그레이션하는 모습.
다음과 같이 ContentProvider
클래스를 사용하는 다른 클래스도 많이 있습니다.
이러한 클래스를 사용하는 경우 애플리케이션에 콘텐츠 제공자를 구현해야 합니다. 동기화 어댑터 프레임워크를 사용할 때 대안으로 스텁 콘텐츠 제공업체를 만들 수도 있습니다. 자세한 내용은 스터브 콘텐츠 제공업체 만들기를 참고하세요. 또한 다음과 같은 경우에는 자체적인 콘텐츠 제공자가 필요합니다.
- 애플리케이션에 맞춤 추천 검색어를 구현하기 위해
- 위젯에 애플리케이션 데이터를 노출하기 위해
- 복잡한 데이터나 파일을 애플리케이션에서 다른 애플리케이션으로 복사하여 붙여넣기
Android 프레임워크에는 오디오, 동영상, 이미지, 개인 연락처 정보 등의 데이터를 관리하는 콘텐츠 제공자가 포함되어 있습니다. 그중 일부는 android.provider
패키지의 참조 문서에서 확인할 수 있습니다. 일부 제한사항이 있지만 이러한 제공자는 모든 Android 애플리케이션에서 액세스할 수 있습니다.
콘텐츠 제공자를 사용하면 구조화된 데이터(예: SQLite 관계형 데이터베이스) 또는 구조화되지 않은 데이터(예: 이미지 파일)를 포함한 다양한 데이터 저장소 소스의 액세스를 관리할 수 있습니다. Android에서 사용 가능한 저장소 유형에 관한 자세한 내용은 데이터 및 파일 저장소 개요 및
데이터 저장소 설계를 참고하세요.
콘텐츠 제공자의 장점
콘텐츠 제공자는 데이터 액세스 권한에 대한 세분화된 제어 기능을 제공합니다. 애플리케이션 내에 있는 콘텐츠 제공자로만 액세스를 제한하거나, 다른 애플리케이션의 데이터에 액세스할 수 있는 포괄적인 권한을 부여하거나, 데이터 읽기 및 쓰기와 관련된 다른 권한을 구성할 수 있습니다. 콘텐츠 제공자를 안전하게 사용하는 방법에 관한 자세한 내용은
데이터 저장을 위한 보안 팁 및
콘텐츠 제공자 권한을 참조하세요.
콘텐츠 제공자를 사용하여 애플리케이션의 여러 데이터 소스에 액세스하기 위한 세부정보를 추상화할 수 있습니다. 예를 들어 애플리케이션은 동영상 및 오디오 파일과 함께 구조화된 레코드를 SQLite 데이터베이스에 저장할 수 있습니다. 콘텐츠 제공업체를 사용하여 이 모든 데이터에 액세스할 수 있습니다.
또한 CursorLoader
객체는 콘텐츠 제공자를 사용하여 비동기 쿼리를 실행한 다음 애플리케이션의 UI 레이어로 결과를 반환합니다. CursorLoader
를 사용하여 백그라운드에서 데이터를 로드하는 방법에 관한 자세한 내용은
로더를 참고하세요.
다음 주제에서는 콘텐츠 제공자에 대해 좀 더 자세히 설명합니다.
-
콘텐츠 제공자 기본사항
- 기존 콘텐츠 제공자를 사용하여 데이터에 액세스하고 데이터를 업데이트하는 방법
-
콘텐츠 제공자 만들기
- 자체 콘텐츠 제공자를 설계하고 구현하는 방법
-
캘린더 제공자 개요
- Android 플랫폼의 일부인 캘린더 제공자에 액세스하는 방법입니다.
-
연락처 제공자
- Android 플랫폼의 일부인 연락처 제공자에 액세스하는 방법
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Content providers can help an application manage access to data stored by itself or\nstored by other apps and provide a way to share data with other apps. They encapsulate the\ndata and provide mechanisms for defining data security. Content providers are the standard\ninterface that connects data in one process with code running in another process.\n\n\nImplementing a content provider has many advantages. Most importantly, you can configure a\ncontent provider to let other applications securely access and modify your app data,\nas illustrated in figure 1.\n\n\n**Figure 1.** Overview diagram of how content providers\nmanage access to storage.\n\n\nUse content providers if you plan to share data. If you don't plan to share data,\nyou don't have to use them, but you might choose to because they provide an abstraction\nthat lets you make modifications to your application data storage\nimplementation without affecting other applications that rely on access to your data.\n\n\nIn this scenario, only your content provider is affected and not the applications that\naccess it. For example, you might swap out a SQLite database for alternative storage, as\nillustrated in figure 2.\n\n\n**Figure 2.** Illustration of migrating content provider storage.\n\n\nA number of other classes rely on the [ContentProvider](/reference/android/content/ContentProvider) class:\n\n- [AbstractThreadedSyncAdapter](/reference/android/content/AbstractThreadedSyncAdapter)\n- [CursorAdapter](/reference/android/widget/CursorAdapter)\n- [CursorLoader](/reference/android/content/CursorLoader)\n\n\nIf you use any of these classes, you need to implement a content provider\nin your application. When working with the sync adapter framework you can also create\na stub content provider as an alternative. For more information, see\n[Create a stub content\nprovider](/training/sync-adapters/creating-stub-provider). In addition, you need your own content provider in the following cases:\n\n- To implement custom search suggestions in your application.\n- To expose your application data to widgets.\n- To copy and paste complex data or files from your application to other applications.\n\n\nThe Android framework includes content providers that manage data such as audio, video, images,\nand personal contact information. You can see some of them listed in the reference\ndocumentation for the\n[android.provider](/reference/android/provider/package-summary)`\n` package. With some restrictions, these providers are accessible to any Android\napplication.\n\n\nA content provider can be used to manage access to a variety of data storage sources, including\nboth structured data, such as a SQLite relational database, or unstructured data such as image\nfiles. For more information about the types of storage available on Android, see the\n[Data and file storage overview](/guide/topics/data/data-storage) and\n[Design data storage](/guide/topics/providers/content-provider-creating#DataStorage).\n\nAdvantages of content providers\n-------------------------------\n\n\nContent providers offer granular control over the permissions for accessing data. You can\nchoose to restrict access to only a content provider that is within your application, grant\nblanket permission to access data from other applications, or configure different permissions\nfor reading and writing data. For more information about using content providers securely, see the\n[security tips for data storage](/privacy-and-security/security-tips#StoringData) and\n[Content provider permissions](/guide/topics/providers/content-provider-basics#Permissions).\n\n\nYou can use a content provider to abstract away the details for accessing different data\nsources in your application. For example, your application might store structured records in a\nSQLite database, as well as video and audio files. You can use a content provider to access all\nof this data.\n\n\nAlso, [CursorLoader](/reference/android/content/CursorLoader) objects rely on content providers to run\nasynchronous queries and then return the results to the UI layer in your application. For more\ninformation about using a `CursorLoader` to load data in the background, see\n[Loaders](/training/load-data-background/setup-loader).\n\n\nThe following topics describe content providers in more detail:\n\n\n**[Content provider basics](/guide/topics/providers/content-provider-basics)**\n:\n How to access and update data using an existing content provider.\n\n\n**[Create a content provider](/guide/topics/providers/content-provider-creating)**\n:\n How to design and implement your own content provider.\n\n\n**[Calendar provider overview](/guide/topics/providers/calendar-provider)**\n:\n How to access the Calendar Provider that is part of the Android platform.\n\n\n**[Contacts Provider](/guide/topics/providers/contacts-provider)**\n:\n How to access the Contacts Provider that is part of the Android platform."]]