RUVIDEO
Поделитесь видео 🙏

Scoped Storage Android 33 java example | How to save image in Android using MediaStore? Tutorial

📁 Обучение 👁️ 20 📅 01.12.2023

Public file storage on Android 10

Do you Want me to Develop Android App for you?
Check out my GIG: https://www.fiverr.com/genericapps/develop-android-app-for-your-bussiness

Plz Subscribe: https://www.youtube.com/@genericapps?sub_confirmation=1

In the past before Android 10 in order to save content, let’s say an image, on a device from our app and make it publicly available to all the apps installed

Those 2 implementations, together with WRITE_EXTERNAL_STORAGE permissions, work until Android 9, while they throw a SecurityException on Android 10.
Since Android 10
On Android 10 things slightly changed: we can still save content in external media directories, but only through the content resolver.
Here is an example of how to do it:
In this new implementation we can see a couple of new content values:
RELATIVE_PATH : Can be used to specify a subfolder in the directory of destination e.g. if we are saving into the pictures directory and we want our content to be saved into Our_subdirectory we can just pass ${DIRECTORY_PICTURES}/Our_subdirectory as in the example shown above.
IS_PENDING : Used to tell the content resolver there is an operation going on. Once we copied the data in the destination file (done in the copyFileData() function), we can set this value to false like shown at the end of the example above.
Copying the data into the destination file can be easily done


We made examples assuming we wanted to save an image file, what about other types of files?
The MediaStore class contains different subclasses for this purpose:
In the previous examples, you could see we were using MediaStore.Images.xyz , so those are the available ones:
MediaStore.Images
MediaStore.Video
MediaStore.Audio
MediaStore.Downloads
As a general rule, I tend to save all the media content in the related subtype folder (so a .mp3 file will use the MediaStore.Audio class) while everything else goes in the downloads folder using the MediaStore.Downloads class.
Notes
Unfortunately, the APIs used in Android 10 are not available in the older versions of Android, which means we need to maintain two different ways of saving content externally, which is not ideal.
In the Android 10 example, we said we add content through the content resolver, and we do so using content values. We can see that we use the VOLUME_EXTERNAL_PRIMARY to get the relative collection uri in which we are going to store our file information.
This value is available only on Android 10, and the Android official documentation states we could use VOLUME_EXTERNAL on older APIs, which will definitely make our lives easier as well as improving our code by not having two completely different implementations to achieve the same result on different Android versions.
Unfortunately, when I tried to use the VOLUME_EXTERNAL the compiler was showing an error saying it is only available on Android 10 ?


Android 10 put a greater emphasis on privacy and security. Android 11 continues this emphasis and gives you many tools to achieve this. One of those tools is scoped storage. This feature impacts your app in a big way if you’re leveraging local file access.

With scoped storage, an app no longer has direct access to all the files in external storage. If an app wants to manipulate a file that it didn’t create, it has to get explicit authorization from the user. These request prompts appear for each file. This provides a new level of control for the user. They can now decide what an app can or cannot do with their files.

Because this can have a potentially heavy impact on existing apps, Android 10 provides an opt-out mechanism. When enabled, it allows an app to work without any of these requirements. The caveat here is that when your app targets API 30 (Android 11), scoped storage starts to be mandatory.

So if your app uses device storage, it’s time to start preparing it for scoped storage.

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Scoped Storage Android 33 java example | How to save image in Android using MediaStore? Tutorial», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.