Skip to content

How to access the asset images from the native code in flutter #31501

Closed
@headspy

Description

@headspy

Hi, I am a newbie at this so, please help me.

For my project, I need to access images (present in the folder named "assets") in native code(Android code) in flutter so that i can set it as my phone wallpaper.

Untitled

I have used assetsmanager to access the file but it is showing me that it can't find any file. Below is the code snippet.

I also added the image in pubspec.yaml under assets.

WallpaperManager wm = null;
wm = WallpaperManager.getInstance(this);

try{
AssetManager assetManager = getAssets();
InputStream is = assetManager.open("assets/wall3.jpg");
Bitmap bitmap = BitmapFactory.decodeStream(is);
wm.setBitmap(bitmap);
}

catch (IOException e){
System.out.println("Exception occurred - 1");
System.out.println(e);
}

image

Where are these files stored.(Ex: /assets/image1.jpg or somewhere else)

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: assetsPackaging, accessing, or using assetsa: existing-appsIntegration with existing apps via the add-to-app flowplatform-androidAndroid applications specifically

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions