Android - Is MediaStore ID a safe way to store inf

2019-07-28 04:53发布

问题:

In my app I store information about an image or an image album by storing it's MediaStore id. Later on I may have to perform operations that require these images/albums. Is the MediaStore id a safe way to keep image\album information? More specifically:

1) If an image/album whose id I have stored gets deleted, is it possible a new picture/album could take this id resulting in me using the wrong picture/album ?

2) when pictures/abums are renamed or moved ( using a file browser on the phone or by connecting to a laptop) do their ids change ?

If so...what measures do I take to avoid these errors ?

回答1:

I've not had direct experience with this, but appears from this SE answer that individual IDs do change when the user moves them, and all IDs may change if the SD media is disconnected and reconnected.

Better, it seems, to store your own unique ID (perhaps by creating a hash value), or, more simply, the filename.