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 accomplish this?
FileOutputStream out = myActivity.openFileOutput(fileTo, Context.MODE_WORLD_READABLE);
Okay more info:
I’m using this:
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "video/*");
And the uri will be the one that I will write to a sdcard location. 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.
That is already
MODE_WORLD_WRITABLEby 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.If you are really writing the file to external storage, just use a
Uripointing to that file.If you are writing the file to internal storage, create a
ContentProviderto serve that file, and use aUripointing to thatContentProvider. Here is a sample application with aContentProviderthat extracts a PDF file fromassets/on first run, then serves up that file viaopenFile()so it can be viewed by a PDF viewer.