Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Copy file to Download directory in android < 10 #170

Closed
ErickLuizA opened this issue Jun 25, 2022 · 9 comments
Closed

[Android] Copy file to Download directory in android < 10 #170

ErickLuizA opened this issue Jun 25, 2022 · 9 comments
Labels
question Questions about the library

Comments

@ErickLuizA
Copy link

Hello,

Before anything, thank you very much for maintaining this library, I really appreciate your work.

At the moment, as far as I understand, the MediaCollection.copyToMediaStore method only truly copies the file to the shared Download directory if the android version is 10 or higher.

Am I wrong about that? Or is there a way to make that happen?
If not, do you have an idea of when this will be possible? Although I don't have much experience with native code, I am willing to help with anything necessary.

Thanks.

@RonRadtke
Copy link
Owner

Hello,
thank you!

Exactly, the MediaCollection API is copying the file to the shared download folder for Android 10 and above.
For lower versions it's copying the file to the apps internal download folder.
You would need these two flags:
UIFileSharingEnabled
and
LSSupportsOpeningDocumentsInPlace

(See https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW20:~:text=3.2%20and%20later.-,UIFileSharingEnabled,-UIFileSharingEnabled%20(Boolean for more information)

@RonRadtke RonRadtke added the question Questions about the library label Jun 25, 2022
@ErickLuizA
Copy link
Author

Hello,

Thanks for answering.

Is there any solution for android to work in a version lower than 10?

Is It possible to implement such functionality?

Using another API that can give access to the external storage when in a lower version or something like that?

@RonRadtke
Copy link
Owner

It's possible yes.
Basically it's just a matter of the directory you're storing the files to.
The problem is currently we're not exporting the paths (see #89)
I am thinking about either offering a new variable like legacydirs which will return the external paths you need.
Will see if I can squeeze it in somewhen next week

@RonRadtke
Copy link
Owner

I'm reopening for now.
I created a branch with changes to expose the old paths: https://github.com/RonRadtke/react-native-blob-util/tree/feature/legacypaths

Would be great if you're able to test it for your purpose. It's so far untested but I'll test it myself this or next week.

@RonRadtke RonRadtke reopened this Jun 27, 2022
@ErickLuizA
Copy link
Author

Hello,

I have tested it here and it's working fine.

It would be cool if when the docs for these new changes are made, the need for runtime permissions is mentioned alongside it.

@RonRadtke
Copy link
Owner

Thanks. But I sadly run into issues myself during testing, realizing that we will get warnings / errors if we try to build it with targetSDK > 29.
So I will have to find another way for getting it to work for older versions.

But you could try using the downloadmanager option. This one should still work

@RonRadtke
Copy link
Owner

Found a way around. Update will be released tomorrow

@RonRadtke
Copy link
Owner

https://github.com/RonRadtke/react-native-blob-util/releases/tag/0.16.2

You can use the Mediastore API now also on old devices to store the file in the public downloads folder.
Or you do it manually, as you prefer.

@oman21
Copy link

oman21 commented Oct 10, 2022

in android < 10 MediaCollection get this error

This is an image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Questions about the library
Projects
None yet
Development

No branches or pull requests

3 participants