-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update 0x05d-Testing-Data-Storage: Internal Storage, External Storage incl. Scoped Storage, APIs and permissions #3179
base: master
Are you sure you want to change the base?
Conversation
… incl. Scoped Storage, APIs and permissions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left only one optional suggestion
> | ||
> If the user uninstalls and reinstalls your app, however, you must request [READ_EXTERNAL_STORAGE](https://developer.android.com/reference/android/Manifest.permission#READ_EXTERNAL_STORAGE) to access the files that your app originally created. This permission request is required because the system considers the file to be attributed to the previously installed version of the app, rather than the newly installed one. | ||
|
||
For example, trying to access a file stored using the `MediaStore` API with a `content://` URI like `content://media/external_primary` would only work as long as the image _belongs_ to the invoking app (due to `owner_package_name` attribute in the `MediaStore`). If the app calls a `content://` URI that does not belong to the app, it will fail with a `SecurityException`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good example. I can't tell for Android devs but wouldn't an example with getExternalFilesDir
be easier here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please post a suggestion with that case as well, we can have both but wanted to definitely highlight this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to suggest the following:
For example, trying to access a file stored using the `MediaStore` API with a `content://` URI like `content://media/external_primary` would only work as long as the image _belongs_ to the invoking app (due to `owner_package_name` attribute in the `MediaStore`). If the app calls a `content://` URI that does not belong to the app, it will fail with a `SecurityException`: | |
For example, if you create a file within the external storage in the following way: | |
```kotlin | |
val path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); | |
val file = File(path, "image.jpg"); | |
FileOutputStream(file).use { | |
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, it) | |
} | |
Accessing this image would only work as long as the image belongs to the invoking app. |
But now when I think of it, the app would require WRITE_EXTERNAL_STORAGE, which isn't possible anymore. I believe that the current example fits just right.
This pull request updates
Document/0x05d-Testing-Data-Storage.md
file, focusing on improving the guidance for handling data storage on Android. The changes include replacing Java examples with Kotlin, expanding on internal and external storage security practices, and updating information on scoped storage and related permissions.Key changes:
Internal Storage:
External Storage:
MediaStore API:
Manifest Permissions:
READ_EXTERNAL_STORAGE
,WRITE_EXTERNAL_STORAGE
, andMANAGE_EXTERNAL_STORAGE
.READ_MEDIA_IMAGES
,READ_MEDIA_VIDEO
, andREAD_MEDIA_AUDIO
introduced in Android 13.