Search code examples
androidpicasso

Can't load image from disk with picasso


At, first i search in Stackoverflow and internet and find many answers but when i try these answers but no answers can solve my problem. in my project i create a directory that name is files.

enter image description here

    Picasso.with(MainActivity.this).load("file:///files/img_4.jpg").error(R.drawable.eboss).into(imgArticle);

or

Picasso.with(MainActivity.this).load("/files/img_4.jpg").error(R.drawable.eboss).into(imgArticle);

or

 File f = new File("files/img_4");
        Picasso.with(MainActivity.this).load(f).error(R.drawable.eboss).into(imgArticle);

or

Picasso.with(MainActivity.this).load("file:/files/img_4.jpg").error(R.drawable.eboss).into(imgArticle);

but nothing work and i only see error image.


Solution

  • You can load image from files too. Picasso allows that.Here is that from Picasso.

    RESOURCE LOADING
    
    Resources, assets, files, content providers are all supported as image sources.
    
    Picasso.with(context).load(R.drawable.landing_screen).into(imageView1);
    Picasso.with(context).load("file:///android_asset/DvpvklR.png").into(imageView2);
    Picasso.with(context).load(new File(...)).into(imageView3);
    

    load(new File(...)) - BUT File here must be the ones that are created in /data/data/package.name/...

    So either copy file to assets or specify path to /data/data/package.name/... or from sdcard. See this to know how to load from sdcard. You can create a file here using getFilessDir().

    I think there is no files/ folder in android project structure. You may like to take a look at Managing Projects Overview.