# 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
* <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
* <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.

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.

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客