Wie lade Bild von URL und speichern Sie diese auf Speicher des Geräts in Android? Sagen Sie mir nicht, dass ich Picasso oder Oerlaibrary benutze. Ich muss: Wenn Gerät Internet-Verbindung bekomme ich Image von der URL zu ImageView laden und auf Speicher des Geräts speichern, sonst muss ich eines der gespeicherten Bild zu ImageView laden. Danke für`s hilftBild von URL laden und auf Speicher in Android
P.S. Tut mir leid, ich kann einige Fehler machen, weil ich kein Englisch kann. Das ist meine Klasse:
public class ImageManager {
String file_path;
Bitmap bitmap = null;
public Bitmap donwoaledImageFromSD() {
File image = new File(Environment.getExternalStorageDirectory().getPath(),file_path);
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bitmap = BitmapFactory.decodeFile(image.getAbsolutePath(),bmOptions);
return bitmap;
}
private void savebitmap() {
File file = new File("first");
file_path = file.getAbsolutePath();
try {
FileOutputStream fileOutputStream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90,fileOutputStream);
} catch (Exception e) {
e.printStackTrace();
}
}
public void fetchImage(final String url, final ImageView iView) {
new AsyncTask<String, Void, Bitmap>() {
protected Bitmap doInBackground(String... iUrl) {
try {
InputStream in = new URL(url).openStream();
bitmap = BitmapFactory.decodeStream(in);
savebitmap();
} catch (Exception e) {
donwoaledImageFromSD();
}
return bitmap;
}
protected void onPostExecute(Bitmap result) {
super.onPostExecute(result);
if (iView != null) {
iView.setImageBitmap(result);
}
}
}.execute(url);
}
}
Y u dont zuverlässige Bibliotheken wie Glide verwenden , Picaso, etc –
Es ist eines der Kriterien nicht verwenden Standart Laibrary (Glide, Picaso, etc) –
Bitte bieten Sie eine [MCVE] demonstrieren, was Sie versucht haben und welche spezifischen Probleme, die Sie aufgetreten sind. – CommonsWare