Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Partition Storage in Android 10

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Today, I will talk to you about how to achieve partition storage in Android 10. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

1. Introduction to the background of partition storage

Google released Android10 release version on September 3, 2019. in order to better protect user data and limit the increase of device redundant files, Android10 version changed the external storage access mode of the device. the new feature of external storage is called partition storage (Scoped Storage). Partition storage redesigns the access mode of external storage files according to the following three principles, which is convenient for users to better manage external storage files.

1.1 better attribution of documents:

The system records which application creates the file, and the application can access the file created by the application without storage permission.

1.2 apply data protection:

Add external storage application private directory file access restrictions. Applications cannot access other external storage private directory files even if they apply for storage permission.

1.3 user data protection:

Add access restrictions on pdf, office, doc and other files. Even if you apply for storage permission, users cannot access pdf, office, doc and other files created by other applications.

two。 Application compatibility mode

There is a certain adaptation cost for partition storage. Google provides a transition solution for the Android10 version. Set the application to run in compatibility mode (see 2.3 for details). Android11 will no longer support this behavior, and each application needs to complete the partition storage adaptation before Android11 release.

Introduction to new features of partition storage

1. Overview of partitioned storage

1.1 the new feature of partition storage redesigns external storage, which is divided into two parts: application private directory and shared directory.

(1) Application private directory: store application private data, external storage application private directory corresponds to Android/data/packagename, internal storage application private directory corresponds to data/data/packagename

(2) shared directory: stores other application accessible files, including media files, document files and other files, corresponding to device DCIM, Pictures, Alarms, Music, Notifications,Podcasts, Ringtones, Movies, Download and other directories

1.2 apply private directory file access

Apply private directory file access in the same way as previous Android versions, and you can obtain resources through file path

1.3 shared directory file access

Shared directory files need to be accessed through MediaStore API or Storage Access Framework

(1) MediaStore API does not need to apply for storage permission to create files under the directory specified in the shared directory or to access the application to create files by itself.

(2) MediaStore API needs to apply for storage permission to access media files (pictures, audio, video) created by other applications in the shared directory. If the storage permission is not applied, the file Uri cannot be queried through ContentResolver. Even if the file Uri is obtained by other means, an exception will be thrown when reading or creating the file.

(3) MediaStore API cannot access non-media files created by other applications (pdf, office, doc, txt, etc.), but can only access them through Storage Access Framework

1.4 other affected changes

(1) Image location information some pictures will contain location information, because location is sensitive to users. Android 10 applications cannot obtain image location information by default in partition storage mode. Applications can obtain picture location information through the following two settings. Apply for ACCESS_MEDIA_LOCATION in manifest and call MediaStore setRequireOriginal (Uri uri) API to update picture Uri.

(2) in MediaStore.Files application partition storage mode, MediaStore.Files collections can only obtain media file information (picture, audio, video), but not non-media (pdf, office, doc, txt, etc.) files.

(3) File Path path access to the affected interface

Enable the new feature of partition storage. Andrioid 10 cannot directly access the resources in the shared directory through the File Path path. The following APIs operate file resources through the File path, which will affect the function. Applications need to use MediaStore or SAF access.

two。 Overview of Android version differences in storage characteristics

3. Compatibility mode

3.1 compatibility Mode Settings

If the application does not complete the external storage adaptation work, it can be temporarily run in compatibility mode. If the application applies for storage permission in compatibility mode, you can have access to the full directory of external storage and run through file access before Android10. The following two methods set the application to run in compatibility mode.

(1) Target is less than or equal to Android 9 (API level 28)

(2) Tagret is greater than or equal to Android 10 (API level 29), and set requestLegacyExternalStorage attribute to true in manifest

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report