MediaStore的RELATIVE_PATH的變量的定義

Android Q的MediaStore類中新增了變量RELATIVE_PATH的定義如下:

String android.provider.MediaStore.MediaColumns.RELATIVE_PATH : "relative_path"

        /**
         * Relative path of this media item within the storage device where it
         * is persisted. For example, an item stored at
         * {@code /storage/0000-0000/DCIM/Vacation/IMG1024.JPG} would have a
         * path of {@code DCIM/Vacation/}.
         * <p>
         * This value should only be used for organizational purposes, and you
         * should not attempt to construct or access a raw filesystem path using
         * this value. If you need to open a media item, use an API like
         * {@link ContentResolver#openFileDescriptor(Uri, String)}.
         * <p>
         * When this value is set to {@code NULL} during an
         * {@link ContentResolver#insert} operation, the newly created item will
         * be placed in a relevant default location based on the type of media
         * being inserted. For example, a {@code image/jpeg} item will be placed
         * under {@link Environment#DIRECTORY_PICTURES}.
         * <p>
         * You can modify this column during an {@link ContentResolver#update}
         * call, which will move the underlying file on disk.
         * <p>
         * In both cases above, content must be placed under a top-level
         * directory that is relevant to the media type. For example, attempting
         * to place a {@code audio/mpeg} file under
         * {@link Environment#DIRECTORY_PICTURES} will be rejected.
         */
        @Column(Cursor.FIELD_TYPE_STRING)
        public static final String RELATIVE_PATH = "relative_path";

註釋翻譯如下:

原文:

Relative path of this media item within the storage device where it is persisted. For example, an item stored at /storage/0000-0000/DCIM/Vacation/IMG1024.JPG would have a path of DCIM/Vacation.

This value should only be used for organizational purposes, and you should not attempt to construct or access a raw filesystem path using this value. If you need to open a media item, use an API like ContentResolver#openFileDescriptor(Uri, String).

When this value is set to NULL during an ContentResolver#insert operation, the newly created item will be placed in a relevant default location based on the type of media being inserted. For example, a image/jpeg item will be placed under Environment#DIRECTORY_PICTURES.

You can modify this column during an ContentResolver#update call, which will move the underlying file on disk.

In both cases above, content must be placed under a top-level directory that is relevant to the media type. For example, attempting to place a audio/mpeg file under Environment#DIRECTORY_PICTURES will be rejected.

譯文:

此媒體項在存儲設備中持久化的相對路徑。例如,存儲在/storage/0000-0000/DCIM/Vacation/IMG1024.JPG中的項的路徑爲DCIM/Vacation。

此值應僅用於組織目的,不應嘗試使用此值構造或訪問原始文件系統路徑。如果需要打開媒體項,請使用類似於ContentResolver#openFileDescriptor(Uri,String)的API。

如果在ContentResolver插入操作中將此值設置爲空,則新創建的項將根據插入的媒體類型放置在相關的默認位置。例如,圖像/jpeg項目將放置在環境目錄圖片下。

您可以在ContentResolver#update調用期間修改此列,該調用將移動磁盤上的基礎文件。

在上述兩種情況下,內容都必須放在與媒體類型相關的頂級目錄下。例如,嘗試將audio/mpeg文件放置在 Environment#DIRECTORY_PICTURES 目錄下將被拒絕。

來自百度翻譯:

https://fanyi.baidu.com/#en/zh/Relative%20path%20of%20this%20media%20item%20within%20the%20storage%20device%20where%20it%20is%20persisted.%20For%20example%2C%20an%20item%20stored%20at%20%2Fstorage%2F0000-0000%2FDCIM%2FVacation%2FIMG1024.JPG%20would%20have%20a%20path%20of%20DCIM%2FVacation.%0A%0AThis%20value%20should%20only%20be%20used%20for%20organizational%20purposes%2C%20and%20you%20should%20not%20attempt%20to%20construct%20or%20access%20a%20raw%20filesystem%20path%20using%20this%20value.%20If%20you%20need%20to%20open%20a%20media%20item%2C%20use%20an%20API%20like%20ContentResolver%23openFileDescriptor(Uri%2C%20String).%0A%0AWhen%20this%20value%20is%20set%20to%20NULL%20during%20an%20ContentResolver%23insert%20operation%2C%20the%20newly%20created%20item%20will%20be%20placed%20in%20a%20relevant%20default%20location%20based%20on%20the%20type%20of%20media%20being%20inserted.%20For%20example%2C%20a%20image%2Fjpeg%20item%20will%20be%20placed%20under%20Environment%23DIRECTORY_PICTURES.%0A%0AYou%20can%20modify%20this%20column%20during%20an%20ContentResolver%23update%20call%2C%20which%20will%20move%20the%20underlying%20file%20on%20disk.%0A%0AIn%20both%20cases%20above%2C%20content%20must%20be%20placed%20under%20a%20top-level%20directory%20that%20is%20relevant%20to%20the%20media%20type.%20For%20example%2C%20attempting%20to%20place%20a%20audio%2Fmpeg%20file%20under%20Environment%23DIRECTORY_PICTURES%20will%20be%20rejected.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章