Create a FileProvider to store an image on Android

Поделиться
HTML-код
  • Опубликовано: 24 мар 2022
  • Create a FileProvider that we can pass to the Camera intent to store an image locally on an Android device/SD Card. I start by giving an overview of why we need to create a FileProvider. A FileProvider can give us a content:// URI, which has more granular permissions than a file:// URI. That is, a content URI can have permissions shared via an intent, where a File can only have permissions set at the File level: all applications get the same permission. After that, I cover android:name, android:authorities, androidx.core.content.FileProvider, android:exported, android:grantUriPermissions, and creating a file_paths.xml file that contains the paths where we want to store our images.

Комментарии • 5

  • @BaldingEagle51
    @BaldingEagle51 11 месяцев назад

    On the documentation page for FileProvider, it specifically states that you should extend FileProvider, or your app might crash. Since you use AndroidX's FileProvider, you don't do that here.

  • @JadenAllen
    @JadenAllen 2 года назад

    So I should be able to use this to open a file that will be opened with an external app? I'm generating a .zip file and I need to be able to open it with a file explorer with a button

  • @kamertonaudiophileplayer847
    @kamertonaudiophileplayer847 Год назад

    Thanks for the great guide. You need to update it only for Android 13, because permissions are changed.

    • @discospiff
      @discospiff  Год назад +1

      Damn, it's already changed? I just made this video a few months ago. ;)
      That's the nature of Android development.

    • @kamertonaudiophileplayer847
      @kamertonaudiophileplayer847 Год назад

      @@discospiff More likely yes, because I do something like: String stragePermission = Utils.android13()?Manifest.permission.READ_MEDIA_AUDIO:Manifest.permission.READ_EXTERNAL_STORAGE; and it has a separate permission for images.