How can I pass JSON animation file from Internal Storage instead of Assets folder in Lottie animation view?
Asked
Active
Viewed 3,951 times
2 Answers
0
Lottie Library only set JSON file from assets folder using fileName attribute. For Instance:
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/anim_iv"
android:layout_width="wrap_content"
android:layout_height="300dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
app:lottie_fileName="sample.json"
app:lottie_autoPlay="true"
app:lottie_loop="true"
app:lottie_imageAssetsFolder="images"
/>
If you tried to set JSON file from Internal or external storage, than it would not work. You have to load all JSON data from JSON file in string and set it to LottieAnimationView using setAnimationFromJson() method, like this-
LottieCompositionFactory.fromJsonString(json,getString(R.string.app_name)).addListener(new LottieListener<LottieComposition>() {
@Override
public void onResult(LottieComposition result) {
animView.setComposition(result);
});

Krishna Vyas
- 1,009
- 8
- 25
-1
You would want something along the lines of
File TEST = new File(Environment.getExternalStorageDirectory(), "TEST");
TEST.mkdir(); // make directory may want to check return value
String path = TEST.getAbsolutePath(); // get absolute path
and permissions
<manifest ...>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
...
</manifest>

Kannan panneer selvam
- 354
- 1
- 5
-
I have already tried this but got this error => java.lang.IllegalStateException: Unable to find file /storage/emulated/0/blast.json – Amin Pinjari Jan 22 '19 at 13:23
-
ok,if you need you can refer this https://stackoverflow.com/questions/33162152/storage-permission-error-in-marshmallow – Kannan panneer selvam Jan 22 '19 at 13:26
-
Thank you for your suggestion but I have already provided the required permissions, I got the access of file but unable to pass it to Lottie animation. – Amin Pinjari Jan 22 '19 at 13:31