공유 데이터 세트 액세스
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Android 11(API 수준 30)부터 시스템은 머신러닝 및 미디어 재생과 같은 사용 사례를 위해 여러 앱에서 액세스할 수 있는 큰 데이터 세트를 캐시합니다. 이 기능은 네트워크와 디스크에서 모두 데이터 중복을 줄이는 데 도움이 됩니다.
앱이 대규모 공유 데이터 세트에 액세스해야 할 때, 새로운 사본을 다운로드할지 판단하기 전에 먼저 이러한 캐시된 데이터 세트(공유 데이터 blob이라고 함)를 찾아볼 수 있습니다. 앱은 BlobStoreManager
의 API를 사용하여 이러한 공유 데이터 세트 기능에 액세스할 수 있습니다.
시스템에서는 공유 데이터 blob을 유지관리하며 이 blob에 액세스할 수 있는 앱을 제어합니다. 앱에서 데이터 blob을 제공하면 다음 메서드 중 하나를 호출하여 액세스할 수 있는 다른 앱을 지정할 수 있습니다.
공유 데이터 blob 액세스
시스템은 BlobHandle
객체를 사용하여 각 공유 데이터 blob을 나타냅니다. BlobHandle
의 각 인스턴스에는 암호화 방식으로 안전한 해시 및 데이터세트에 관한 일부 식별 세부정보가 있습니다.
공유 데이터 blob에 액세스하려면 서버에서 식별 세부정보를 다운로드합니다. 이 세부정보를 사용하여 데이터세트를 시스템에서 이미 사용할 수 있는지 확인합니다.
다음 단계는 데이터를 사용할 수 있는지 여부에 따라 다릅니다.
데이터세트 사용 가능
이미 기기에서 데이터세트를 사용할 수 있는 경우 다음 코드 스니펫과 같이 시스템에서 데이터세트에 액세스합니다.
Kotlin
val blobStoreManager =
getSystemService(Context.BLOB_STORE_SERVICE) as BlobStoreManager
// The label "Sample photos" is visible to the user.
val blobHandle = BlobHandle.createWithSha256(sha256DigestBytes,
"Sample photos",
System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1),
"photoTrainingDataset")
try {
val input = ParcelFileDescriptor.AutoCloseInputStream(
blobStoreManager.openBlob(blobHandle))
useDataset(input)
}
자바
BlobStoreManager blobStoreManager =
((BlobStoreManager) getSystemService(Context.BLOB_STORE_SERVICE));
if (blobStoreManager != null) {
// The label "Sample photos" is visible to the user.
BlobHandle blobHandle = BlobHandle.createWithSha256(
sha256DigestBytes,
"Sample photos",
System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1),
"photoTrainingDataset");
try (InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(
blobStoreManager.openBlob(blobHandle))) {
useDataset(input);
}
}
데이터 세트 사용 불가능
데이터세트를 사용할 수 없는 경우 서버에서 다운로드한 후 다음 코드 스니펫과 같이 시스템에 제공합니다.
Kotlin
val sessionId = blobStoreManager.createSession(blobHandle)
try {
val session = blobStoreManager.openSession(sessionId)
try {
// For this example, write 200 MiB at the beginning of the file.
val output = ParcelFileDescriptor.AutoCloseOutputStream(
session.openWrite(0, 1024 * 1024 * 200))
writeDataset(output)
session.apply {
allowSameSignatureAccess()
allowPackageAccess(your-app-package,
app-certificate)
allowPackageAccess(some-other-app-package,
app-certificate)
commit(mainExecutor, callback)
}
}
}
Java
long sessionId = blobStoreManager.createSession(blobHandle);
try (BlobStoreManager.Session session =
blobStoreManager.openSession(sessionId)) {
// For this example, write 200 MiB at the beginning of the file.
try (OutputStream output = new ParcelFileDescriptor.AutoCloseOutputStream(
session.openWrite(0, 1024 * 1024 * 200)))
writeDataset(output);
session.allowSameSignatureAccess();
session.allowPackageAccess(your-app-package,
app-certificate);
session.allowPackageAccess(some-other-app-package,
app-certificate);
session.commit(getMainExecutor(), callback);
}
}
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-08-21(UTC)
[null,null,["최종 업데이트: 2025-08-21(UTC)"],[],[],null,["# Access shared datasets\n\nStarting in Android 11 (API level 30), the system caches large datasets that\nmultiple apps might access for use cases like machine learning and media\nplayback. This functionality helps reduce data redundancy, both over the network\nand on disk.\n\nWhen your app needs access to a shared large dataset, it can first look for\nthese cached datasets, called *shared data blobs* , before determining whether to\ndownload a new copy. Apps can access these shared datasets functionality using\nthe APIs in [`BlobStoreManager`](/reference/android/app/blob/BlobStoreManager).\n\nThe system maintains the shared data blobs and controls which apps can access\nthem. When your app contributes data blobs, you can indicate which other apps\nshould have access by calling one of the following methods:\n\n- To grant access to a specific set of apps on a device, pass the package names of these apps into [`allowPackageAccess()`](/reference/android/app/blob/BlobStoreManager.Session#allowPackageAccess(java.lang.String,%20byte%5B%5D)).\n- To allow only apps whose certificates are signed using the same key as the one used for your app---such as an app suite that you manage---call [`allowSameSignatureAccess()`](/reference/android/app/blob/BlobStoreManager.Session#allowSameSignatureAccess()).\n- To grant access to all apps on a device, call [`allowPublicAccess()`](/reference/android/app/blob/BlobStoreManager.Session#allowPublicAccess()).\n\nAccess shared data blobs\n------------------------\n\nThe system represents each shared data blob using a\n[`BlobHandle`](/reference/android/app/blob/BlobHandle) object. Each instance of `BlobHandle`\ncontains a cryptographically-secure hash and some identifying details for the\ndataset.\n\nTo access shared data blobs, download identifying details from the server. Using\nthese details, check whether the dataset is already available on the system.\n\nThe next step depends on whether data is available.\n\n### Dataset available\n\nIf the dataset is already available on the device, then access it from the system,\nas shown in the following code snippet: \n\n### Kotlin\n\n```kotlin\nval blobStoreManager =\n getSystemService(Context.BLOB_STORE_SERVICE) as BlobStoreManager\n// The label \"Sample photos\" is visible to the user.\nval blobHandle = BlobHandle.createWithSha256(sha256DigestBytes,\n \"Sample photos\",\n System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1),\n \"photoTrainingDataset\")\ntry {\n val input = ParcelFileDescriptor.AutoCloseInputStream(\n blobStoreManager.openBlob(blobHandle))\n useDataset(input)\n}\n```\n\n### Java\n\n```java\nBlobStoreManager blobStoreManager =\n ((BlobStoreManager) getSystemService(Context.BLOB_STORE_SERVICE));\nif (blobStoreManager != null) {\n // The label \"Sample photos\" is visible to the user.\n BlobHandle blobHandle = BlobHandle.createWithSha256(\n sha256DigestBytes,\n \"Sample photos\",\n System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1),\n \"photoTrainingDataset\");\n try (InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(\n blobStoreManager.openBlob(blobHandle))) {\n useDataset(input);\n }\n}\n```\n\n### Dataset unavailable\n\nIf the dataset isn't available, then download it from the server and contribute it\nto the system, as shown in the following code snippet: \n\n### Kotlin\n\n```kotlin\nval sessionId = blobStoreManager.createSession(blobHandle)\ntry {\n val session = blobStoreManager.openSession(sessionId)\n try {\n // For this example, write 200 MiB at the beginning of the file.\n val output = ParcelFileDescriptor.AutoCloseOutputStream(\n session.openWrite(0, 1024 * 1024 * 200))\n writeDataset(output)\n\n session.apply {\n allowSameSignatureAccess()\n allowPackageAccess(your-app-package,\n app-certificate)\n allowPackageAccess(some-other-app-package,\n app-certificate)\n commit(mainExecutor, callback)\n }\n }\n}\n```\n\n### Java\n\n```java\nlong sessionId = blobStoreManager.createSession(blobHandle);\ntry (BlobStoreManager.Session session =\n blobStoreManager.openSession(sessionId)) {\n // For this example, write 200 MiB at the beginning of the file.\n try (OutputStream output = new ParcelFileDescriptor.AutoCloseOutputStream(\n session.openWrite(0, 1024 * 1024 * 200)))\n writeDataset(output);\n session.allowSameSignatureAccess();\n session.allowPackageAccess(your-app-package,\n app-certificate);\n session.allowPackageAccess(some-other-app-package,\n app-certificate);\n session.commit(getMainExecutor(), callback);\n }\n}\n```"]]