Get a Content URI from a File URI?

后端 未结 3 657
执笔经年
执笔经年 2021-02-09 06:36

I am using the DownloadManager to download an image to the system\'s gallery and then in the Broadcast receiver (once the download succeeds) using an Intent to set the image as

3条回答
  •  失恋的感觉
    2021-02-09 07:34

    I'm not sure about the technique you are using to set the wallpaper but the easiest way is probably to use WallpaperManager.setStream() which doesn't require any URI.

    Also note that a file URI only works between apps if the file is publicly accessible so a content URI is a more general solution.

    Using a content URI implies that a ContentProvider will serve the file. Which one depends on where your file is located.

    If your app has a direct read access to the file, you can implement a content provider in your app by using for example the FileProvider class of the support library, but this should really only be used if the file is located in the private data storage of your app.

    If the image is added to the system media gallery, you should probably use the URI provided by the MediaStore.

提交回复
热议问题