0

I need to download a video to a file without storing it on the device, only to the memory so I can share it without the need of permission:

    lateinit var videoFile: InputStream // or what ever type it is suppose to be!

var videoFileUrl = "https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4"
    
    // download the video to videoFile
    
    val sharingIntent = Intent(Intent.ACTION_SEND)
    sharingIntent.type = "video/mp4"
    sharingIntent.putExtra(Intent.EXTRA_STREAM, videoFile)
    context.startActivity(Intent.createChooser(sharingIntent,"Share Video"))

I've seen other apps doing it so I know a permission isn't required. Please help!

Eduard Unruh
  • 985
  • 1
  • 14
  • 35

2 Answers2

0
  • store files in cache not need permission of storage
  • youtube-dl it's Backend of any app that allows download from YouTube/fb....
nextloop
  • 166
  • 9
0

I need to download a video to a file without storing it on the device

By definition, that is impossible. A file is "storing it on the device". This is true for every major operating system.

so I can share it without the need of permission

You can write whatever files you like to specific places on the device without permissions. These places are identified via methods on Context, such as getFilesDir() and getCacheDir(). See the documentation.

You can download to those locations using your favorite HTTP client, such as OkHttp.

You can then share the file from your chosen location using FileProvider. See the documentation.

Also, when you do share, use a concrete MIME type, not a wildcard, as in your example (video/*). It is your content that you are sharing, so it is your job to specify what sort of content it is.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • "use a concrete MIME type" ok I edited it, it will always be mp4, a code example how to download the video would be nice though. I can't stand the awful google/android docs it's a mess – Eduard Unruh Jul 05 '21 at 23:08
  • @EduardUnruh: "a code example how to download the video would be nice though" -- I linked to [an answer](https://stackoverflow.com/a/29012988/115145) that demonstrates the core portion of this. OkHttp overall has [quite a bit of documentation](https://square.github.io/okhttp/). "I can't stand the awful google/android docs it's a mess" -- then, perhaps you should read books on Android app development, or take a course on Android app development. – CommonsWare Jul 05 '21 at 23:13
  • Well I'm stuck at Builder() I don't know what to import for this crap there are multiple options with okhttp in it. Android is so awful seriously – Eduard Unruh Jul 05 '21 at 23:24