안녕하세요.
Down("http://p.stcgroup.co.kr/test.jpg", "test.jpg");
public void Down(String strURL, String strFilename){
try {
String DownloadURL = strURL;
//fileName = "/mnt/sdcard/"+strFilename;
fileName = GalleryPath+"/"+strFilename;
//fileName = FilePath+strFilename;
InputStream inputStream = new URL("DownloadURL).openStream();
File file = new File(fileName);
OutputStream out = new FileOutputStream(file);
saveRemoteFile(inputStream, out);
out.close();
rstMSG.setText("File Write "+strFilename);
} catch(Exception e){
rstMSG.setText("File Write Failed! "+strFilename);
e.printStackTrace();
}
}
public void saveRemoteFile(InputStream is, OutputStream os) throws IOException {
int c = 0;
while((c = is.read()) != -1)
os.write(c);
os.flush();
}
이걸 이용해서 다운로드를 하는데 다운로드까지는 잘되는 듯한데 해당 파일을 선택하면 이미지가 나오지 않습니다.
왜 그러는 건가요???




해결했습니다.
MediaScannerConnectionClient mediaScannerClient = new MediaScannerConnectionClient() {
private MediaScannerConnection msc = null;
{
msc = new MediaScannerConnection(getApplicationContext(), this);
msc.connect();
}
public void onMediaScannerConnected(){
msc.scanFile(FileNames, null);
}
public void onScanCompleted(String path, Uri uri) {
//This is where you get your content uri
Log.d("IMG", uri.toString());
msc.disconnect();
}
};
이렇게 스캔을 해줘야 하는군요~~~