我正在研究android中的图像壁纸应用程序当我从url下载图像时,它会在移动设备上显示图像,但大部分时间它都没有显示但是当我将我的手机连接到计算机时它在指定的文件夹中。 谢谢提前期待回答。
这是我下载图片的代码。
protected Void doInBackground(Void... arg0) {
FileOutputStream fileOutput = null;
try {
// set the path where we want to save the file
// in this case, going to save it on the root directory of the
// sd card.
File dir = Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
String filename = _imagePaths[FullScreenImage.position]
.substring(_imagePaths[FullScreenImage.position]
.lastIndexOf("/"));
if (!dir.exists())
dir.mkdirs();
File file = new File(dir, filename);
Log.i("Local filename:", "" + filename);
// this will be used to write the downloaded data into the file
// we created
fileOutput = new FileOutputStream(file);
Bitmap mybitmap = imageLoader.getBitmap(
_imagePaths[FullScreenImage.position], 800, 480);
mybitmap.compress(CompressFormat.JPEG, 100, fileOutput);
// close the output stream when done
// catch some possible errors...
} catch (IOException e) {
Log.e("Download Image catch > ", e.getMessage());
} finally {
if (fileOutput != null) {
try {
fileOutput.flush();
fileOutput.close();
} catch (IOException e) {
// TODO Auto-generated catch block
Log.e("Download Image catch > ", e.getMessage());
}
}
}
return null;
}
答案 0 :(得分:0)
使用MediaScannerConnection.scanFile()
通知系统有关新媒体文件的信息。