whit ANDROID previous kitkat I was able to store an image on sd-card 
without problem, now, instead, I've a lot of difficult.

I can't understand how use a new Access Store Framework of Android Lollipop 
and I don't know if it is useful to case of mine.

This code below is a part of my project and it's worked perfectly

    
private Bitmap getBitmap(String url, String image){
    
    String root = Environment.getExternalStorageDirectory().toString();
    root = "/mnt/extSdCard/";
    
    
    Bitmap bitmap = null;
    
    File f=fileCache.getFile(url);
    
    //from SD cache
    bitmap = decodeFile(f);
    if(bitmap!=null)
    return bitmap;
    
    
    try{
    bitmap = BitmapFactory.decodeFile(root + image);
    if(bitmap!=null){
    return bitmap;
    }
    }catch (Exception e) {
    e.printStackTrace();
    }
    
    //from web
    if (netInfo != null && netInfo.isConnectedOrConnecting()) {
    Foto foto = new Foto();
    try {
    try{
    
    foto = new ObjectMapper().readValue(new URL("........."),
     Foto.class);
    
    if(foto!=null){
    String[] values = image.split("/");
    File dir = new File(root + values[0]);
    if (!dir.exists()) {
       dir.mkdir();
       String fname = values[1];
    File file = new File (dir, fname);
    bitmap = BitmapFactory.decodeByteArray(foto.getFoto(), 0, foto.getFoto
().length);
    try {
    FileOutputStream out = new FileOutputStream(file);
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
    out.flush();
    out.close();
    
    } catch (Exception e) {
    e.printStackTrace();
    }
    }else{
    String fname = values[1];
    File file = new File (dir, fname);
    bitmap = BitmapFactory.decodeByteArray(foto.getFoto(), 0, foto.getFoto
().length);
    try {
    FileOutputStream out = new FileOutputStream(file);
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
    out.flush();
    out.close();
    
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    
    //bitmap = decodeFile(f);
    return bitmap;
    }else{
    return bitmap;
    }
    }catch(Exception e){
    e.printStackTrace();
    return null;
    }
    
    
    } catch (Exception ex){
    if (ex instanceof SQLiteConstraintException){
    bitmap = BitmapFactory.decodeByteArray(foto.getFoto(), 0, foto.getFoto
().length);
    return bitmap;
    }else{
    ex.printStackTrace();
    return null;
    }
    }
    }else{
    return bitmap;
    }
    }
Android Lollipop save image downloaded in background on SD-CARD


If I use `Environment.getExternalStorageDirectory().getAbsolutePath();` I 
can't get path of sd-card.

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/b129f74e-7c97-433d-9933-7cd8e1918ac8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to