Android: Alternative to the deprecated Context.MODE_WORLD_READABLE?

前端 未结 3 1711
清酒与你
清酒与你 2020-12-07 00:59

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

3条回答
  •  北海茫月
    2020-12-07 01:15

    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.

提交回复
热议问题