Uri on Activity.onActivityResult(int requestCode,

2019-08-18 02:49发布

问题:

I have some doubts on the reliability of content providers in Android.

1 - Is it possible for different Documents having the same Uri?

For instance. A user has 2 images in the device:

content://com.android.providers.media.documents/document/image%AAAAA

and

content://com.android.providers.media.documents/document/image%BBBBB

Supposing a scenario where AAAAA would point to a file, then the user erases that file.

User then creates a new file in the system, and that new file receives the AAAAA Uri.

Can this scenario happen?

Or are they sequentially generated so that CCCCC DDDDDetc.. gets created first, in a way that I can trust Uri's to always point to the same file instance (or null if no document can be found by that Uri)?

2 - Is it possible for an Uri pointing to a document that has been significantly altered?

Can a document, that once was Audio, and now is an Image, have the same identifier that once had? I do not mean that the user has changed the file content, but rather an implicit intent gave me a Uri, can I trust that Uri to be unique, for that document in that device?

回答1:

Can this scenario happen?

Yes.

Can a document, that once was Audio, and now is an Image, have the same identifier that once had?

Yes.

Note that the same thing holds true for pretty much everything else in computers. For example, a URL can be reused to point to different Web content, including content with a different MIME type.