I'm using FileProvider
to share files with other apps. I need to include these files with the apk. Since FileProvider
gets files from internal storage /data/data/<pkg-name>
, is there a way to preload these files? So far the only method I found is to first include the files in the raw/assets directory, then programmatically move the files over to internal storage.
Is this the only way, or is there a better recommended method? Can FileProvider transfer files from the assets directory?
Asked
Active
Viewed 822 times
1

prostock
- 9,327
- 19
- 70
- 118
-
1This may help you. CWAC-Provider https://github.com/commonsguy/cwac-provider – Fr099y Aug 23 '17 at 06:05
-
Why can't you download them from some server when application is starting for first time? There is no point in including file in your app if it is not part of resources, all files can be downloaded and saved into any folder you wish. – Akash Kava Aug 24 '17 at 08:01
2 Answers
2
You cannot use FileProvider
to transfer file from Asset Directory. You will have to implement your own ContentProvider
.
Here are similar questions with answers that can help you:
You can also use CWAC-Provider which offers a class that handles Assets: https://github.com/commonsguy/cwac-provider/blob/master/provider/src/main/java/com/commonsware/cwac/provider/StreamProvider.java

Arnaud Develay
- 3,920
- 2
- 15
- 27
0
A different approach may be the usage of APK Expansion Files: Expansion Files
It allows you to ship additional files with your app, especially if your APK hit the 100 MB limit.
Expansion files are saved in the following path: <shared-storage>/Android/obb/<package-name>/
, which can be retrieved via getObbDir().

Christopher
- 9,682
- 7
- 47
- 76