我正在下载保存图片,但是当我打开下载应用程序时,我看不到文件。我尝试使用MediaScannerConnection进行扫描,但仍然没有出现。我的代码在哪里。请帮忙
private void createPNGFile()
{
File downloadPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File createPNGImage = new File(downloadPath.getAbsolutePath(),"image.png");
try {
InputStream is;
is = getResources().openRawResource(R.raw.icon);
OutputStream os = new FileOutputStream(createPNGImage);
byte[] data = new byte[is.available()];
is.read(data);
os.write(data);
is.close();
os.close();
Toast.makeText(this, "File Created (Path): " + createPNGImage.getAbsolutePath(), Toast.LENGTH_LONG).show();
scanFiles(createPNGImage);
}catch(IOException e)
{
}
}
private void scanFiles(final File fileObj)
{
MediaScannerConnection.scanFile(this, new String[]{
fileObj.getAbsolutePath()},
null, new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri)
{
Log.d("Media Scan", "Scan Completed" + fileObj.getAbsolutePath());
}
});
}
答案 0 :(得分:0)
保存图片后尝试运行以下代码:
Found2