0

Google Photos is able to restore your file to an album even if you rename it despite the photo not being in that directory.

To make this possible one could use a FileObserver, but since you can't have a service run indefinitely how would you be able to realise a rename operation on a directory that happens when your application isn't in use.

The other option would be to generate an ID for the directory that remains consistent irrespective of a rename, but how?

Chris Rohit Brendan
  • 893
  • 1
  • 9
  • 20

1 Answers1

0

You can give each directory a unique id, which won't change after a file name. There's a UUID class built into Java that allows you to generate these ids.

For example:

UUID uniqueId = UUID.randomUUID();
Bimde
  • 722
  • 8
  • 20
  • random ID would be of no use since the only way to attach it to directory with be either writing that into preferences or SQL database. But if a directory's name changes, how will I know that the renamed directory points to the ID I generated early on? – Chris Rohit Brendan Sep 12 '18 at 11:49
  • I need some data point that belongs to a directory that can be used to uniquely identify it despite renames, but I don't not know what they are – Chris Rohit Brendan Sep 12 '18 at 11:53
  • Can't you add a field to the directory object / table called `id`, and store a `UUID` in that field? – Bimde Sep 12 '18 at 12:14
  • Also what do you mean by `you don't know what there are`? – Bimde Sep 12 '18 at 12:16
  • If I add an ID it's pointless because how will I update the row for a specific ID without being able to say that the the new directory I have found is actually the same as the previous directory unless there's some relationship between the ID and the old and new directory. The ideal option would be some unique information that a directory has even after file changes such as rename that I can use to identify it even if it changes. – Chris Rohit Brendan Sep 12 '18 at 12:23
  • I must be misunderstanding your question. Isn't there only one directory here, just that that directory is renamed? When the directory is renamed, the `id` should stay the same. And you could use that `id` to retrieve the photos. – Bimde Sep 12 '18 at 12:28
  • I wasn't quite clear with the question. I'm reading from the tables that belong to the MediaStore. I'm taking the parent file derived from the path of the first image in a specific BUCKET_ID as the album directory and path. Since I cannot control or maintain these tables, if the album is renamed when my application isn't alive I'm not able to trace that it has changed and update only some columns. – Chris Rohit Brendan Sep 12 '18 at 12:34
  • A service isn't allowed to run for extended periods so it's a no go if I want to update information. Otherwise I'd have use a Fileobserver and a random generated ID to maintain the information while the ID remains the same. – Chris Rohit Brendan Sep 12 '18 at 12:35
  • You should try adding this information into the question, and providing an example for a situation where you have a problem. Then maybe myself / someone else would be able to help you. – Bimde Sep 12 '18 at 12:42