I am writing a native module for react-native app. I’m new to react-native and android development in general.
Inside of a module class I created a method that opens camera activity by using intent MediaStore.ACTION_VIDEO_CAPTURE
and calling startActivityForResult
like this:
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
Bundle bundle = new Bundle();
reactContext.startActivityForResult(intent, 1);
This code works. However, I need to access all videos recorded with this app, so I decided that storing them in app-specific folder is more suitable then providing users access to all videos on a file system (default saving location shares space with all other video files on a system). As suggested by documentation I decided to use intent extra MediaStore.EXTRA_OUTPUT
.
So I added the following code:
File folder = reactContext.getFilesDir();
File file = new File(folder+"/test.mp4");
Uri uri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
Running this code fails with the following error:
file:///data/user/0/com.myapp/files/test.mp4 exposed beyond app through ClipData.Item.getUri()
After googling this error, I found this question. Accepted answer explains that this error is thrown since sdk 24 (I test on a device of sdk 30) when you get the uri of a file outside your app storage.
I conclude that I don’t quite understand what is supposed to be an app’s storage. According the documentation I assume that what is returned by context.getFilesDir()
satisfies definition of an app storage. But it seems like I am wrong.
There are also two suggested solutions (changing API policy or using FileProvider
) to use in order to ”just make it work”, but the question I am asking is: "What am I missing with understanding the idea of app storage?" Or maybe, there’s another API restriction arrived with later versions of sdk (as I mentioned I test on a device with sdk 30)? Or it is due to some react-native reason?
I would appreciate references to specific sections of android or react-native documentation or any other explanation to the described situation.
Thanks in advance.