mit ANDROID vorherige kitkat Ich konnte ein Bild auf SD-Karte ohne Problem speichern, jetzt habe ich stattdessen eine Menge schwierig.Android Lollipop speichern Bild im Hintergrund heruntergeladen auf SD-CARD
Ich kann nicht verstehen, wie ein neues Access Store Framework von Android Lollipop verwenden und ich weiß nicht, ob es für meinen Fall nützlich ist.
Dieser Code unten ist ein Teil von meinem Projekt und es ist perfekt
arbeitetprivate 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("http://www.xxxxxx.yyyy/project/script.php?id="+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;
}
}
Wie ich die ASF neue ändern von Android zu verwenden ??
Wenn ich Environment.getExternalStorageDirectory().getAbsolutePath();
benutze kann ich nicht Pfad von SD-Karte bekommen.
Dank
Was ist der Fehler, dem Sie jetzt gegenüberstehen? Warum weisen Sie den Root-Wert einer fest codierten Zeichenfolge zu? Verwenden Sie dieses Environment.getExternalStorageDirectory(). GetAbsolutePath(); – Stallion
wenn ich 'Environment.getExternalStorageDirectory() verwenden. GetAbsolutePath();' Ich kann SD-Karte Pfad –