android / android/codelab-android-workmanager

Android 8.1.0 "API 27" (Permision denial: android.permission.WRITE_EXTERNAL_STORAGE don't work)

Open
#307 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
557
Forks
242
PR merge metrics
No merged PRs in 30d

Description

I catch an error on API 27:

2022-10-05 13:49:41.061 16988-17081/com.example.background E/MediaStore: Failed to insert image
java.lang.SecurityException: Permission Denial: writing com.android.providers.media.MediaProvider uri content://media/external/images/media from pid=16988, uid=10116 requires android.permission.WRITE_EXTERNAL_STORAGE, or grantUriPermission()
at android.os.Parcel.readException(Parcel.java:2013)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
at android.content.ContentProviderProxy.insert(ContentProviderNative.java:476)
at android.content.ContentResolver.insert(ContentResolver.java:1539)
at android.provider.MediaStore$Images$Media.insertImage(MediaStore.java:993)
at com.example.background.workers.SaveImageToFileWorker.doWork(SaveImageToFileWorker.kt:40)
at androidx.work.Worker$1.run(Worker.java:86)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
2022-10-05 13:49:41.061 16988-17081/com.example.background E/SaveImageToFileWorker: Writing to MediaStore failed

This permission is mensioned in manifest (see screenshot)
зображення

How to fix this error on API 27?

Contributor guide

Open the contributing guide

Research direction

Start at SaveImageToFileWorker.kt line 40, where the API 27 stack trace shows the MediaStore write failing, and inspect the manifest permission declaration. Reproduce the failure on Android 8.1/API 27; done means the worker can write the image to MediaStore without the reported SecurityException.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.