Images
Voltra provides three different approaches for including images in your Android widgets, each with different trade-offs and use cases:
- Build-time asset copying: Best for static icons and assets known at build time
- Runtime preloading: Best for dynamic images from remote URLs
- Base64 encoding: Best for small, generated images
Build-time asset copying
Place images in the /assets/voltra-android/ directory and they'll be automatically processed and copied to the Android drawable resources during build.
Here's how build-time asset copying works:
- Images in
/assets/voltra-android/are automatically detected during build (runnpx expo prebuildto apply changes). - Filenames are sanitized to be compatible with Android resource naming rules (lowercase, underscores only).
- SVGs are automatically converted to Android Vector Drawables (XML).
- Images are copied to
res/drawable/in the native Android project.
Naming & Sanitization
Android drawable resources have strict naming conventions. Voltra automatically handles this for you:
- Sanitization: Uppercase letters are converted to lowercase. Hyphens and other special characters are replaced with underscores.
- Flattening: Subdirectories are flattened into the resource name to avoid conflicts.
Examples:
Supported Formats
- Bitmap:
.png,.jpg,.jpeg,.gif,.webp - Vector:
.svg(converted to Vector Drawable),.xml(native Vector Drawable)
Usage
Reference these images using their sanitized name in the assetName property. You do not need to include the file extension.
Runtime preloading
For dynamic images from remote URLs, use Voltra's image preloading API to cache images locally.
The image preloading system works by:
- Downloading images from URLs to the app's internal cache.
- Making images available to widgets via a local content provider.
- Providing APIs to reload widgets when new images are ready.
Once images are preloaded, reference them using the key you provided:
For detailed API documentation, see Image Preloading.
Base64 encoding
You can also embed images directly as base64-encoded strings. This is useful for small, generated images or when you want to avoid file management for very simple assets.
