从我想要存储的WebView
中的网址加载图片但不存储。
这是我的代码。
Uri uri="http://202.87.34.17/MobileDetect/Wallpaper/Wallpaper_01.jpg";
widget29=(WebView)findViewById(R.id.widget29);
widget29.loadUrl(IMAGE);
save();
try{
String path = Environment.getExternalStorageDirectory().toString();
OutputStream fOut = null;
File file = new File(path, "/sdcard"+IMAGE_FILENAME+".jpg");
fOut = new FileOutputStream(file);
Bitmap mBitmap = null;
mBitmap.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
fOut.flush();
fOut.close();
MediaStore.Images.Media.insertImage(getContentResolver(),
file.getAbsolutePath(), file.getName(),file.getName());
} catch (Exception e) {
e.printStackTrace();
}
答案 0 :(得分:0)
我不确定,但是您可能需要等到图像下载后再调用保存功能?我对Android没有经验,所以我不知道它是否会立即继续,或者在代码继续之前等待图像完成。
但那就是我要看的地方。也许你可以添加一些"回调"当"图像下载完成"。
时,或者提出某种事件这有意义吗?