Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Commit d41f219

Browse files
Use context instead of applicationContext
A test uses local resources. That's why we can't use applicationContext here.
1 parent e52cdb3 commit d41f219

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

WorkManagerSample/lib/src/main/java/com/example/background/workers/filters/BaseFilterWorker.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,14 @@ abstract class BaseFilterWorker(context: Context, parameters: WorkerParameters)
175175
resourceUri: String
176176
): InputStream? {
177177

178-
val appContext = context.applicationContext
179178
// If the resourceUri is an Android asset URI, then use AssetManager to get a handle to
180179
// the input stream. (Stock Images are Asset URIs).
181180
return if (resourceUri.startsWith(ASSET_PREFIX)) {
182-
val assetManager = appContext.resources.assets
181+
val assetManager = context.resources.assets
183182
assetManager.open(resourceUri.substring(ASSET_PREFIX.length))
184183
} else {
185184
// Not an Android asset Uri. Use a ContentResolver to get a handle to the input stream.
186-
val resolver = appContext.contentResolver
185+
val resolver = context.contentResolver
187186
resolver.openInputStream(Uri.parse(resourceUri))
188187
}
189188
}

0 commit comments

Comments
 (0)