From here I know a way to write a file and be accessible to other app and other intent, but now that the Context.MODE_WORLD_READABLE is deprecated how can I safely accomplis
And the uri will be the one that I will write to a sdcard location.
That is already MODE_WORLD_WRITABLE
by default. Also note that the code you have listed (openFileOutput()
) does not write to external storage (what you incorrectly call "sdcard"). openFileOutput()
is for internal storage.
And the video will come from the application so problem is, if this is now not allowed, how can I write the file and view it.
If you are really writing the file to external storage, just use a Uri
pointing to that file.
If you are writing the file to internal storage, create a ContentProvider
to serve that file, and use a Uri
pointing to that ContentProvider
. Here is a sample application with a ContentProvider
that extracts a PDF file from assets/
on first run, then serves up that file via openFile()
so it can be viewed by a PDF viewer.
It seems to look like the docs are clear about it.
This constant was deprecated in API level 17.
Creating world-readable files is very dangerous, and likely to cause security holes in applications. It is strongly discouraged; instead, applications should use more formal mechanism for interactions such as ContentProvider, BroadcastReceiver, and Service. There are no guarantees that this access mode will remain on a file, such as when it goes through a backup and restore. File creation mode: allow all other applications to have read access to the created file.
Save your video in your internal memory using:
openFileOutput("test.mp4", "MODE_PRIVATE");
Then do this:
String path = context.getFilesDir().getAbsolutePath() + "/test.mp4"; // path to the root of internal memory.
File f = new File(path);
f.setReadable(true, false);
Intent playIntent ....
playIntent.setType("video/*");
playIntent.setData(Uri.fromFile(f));
Good Luck.