Download the vector transferred to the image from the SD card

I want to show a vector image (say vectorimage.xml) in an image image from an SD card. Please give some insights on how to do this in Android. I already tried: -

String imagePath = Environment.getExternalStorageDirectory() + "/ folder/productImage.xml"; bitmapImage = BitmapFactory.decodeFile(imagePath); Drawable bgrImageDrawable = new BitmapDrawable(bitmapImage); 

The above code snippet does not work as bitmapImage comes as null.

+6
source share
1 answer

BitmapFactory cannot load vector drawings. You must use the VectorDrawable or VectorDrawableCompat class. To download a vector drawing, you need to use the xml downloader.

Some parsers, like those needed for resources, require a precompiled xml binary. You can find them in the apk file when you put a vector that can be pulled into the resource directory.

Here is an example, to download it from assets, you should be able to use a similar code to download from an SD card.

 final XmlResourceParser parser = context.getAssets().openXmlResourceParser("assets/folder/image.xml"); drawable = VectorDrawableCompat.createFromXml(context.getResources(), parser); 

This requires at least Android 5.0.

+3
source

All Articles