2014-07-09 3 views
1

SD 카드에 저장된 다운로드 파일의 경로를 저장하려고하지만 검색하려고 할 때 문제가 있습니다. 비트 맵으로 변환하려고하면 파일이 SD 카드에 있어도 파일을 찾을 수 없다고 말합니다.SQLite 데이터베이스에서 이미지 저장 및 검색

파일 예 :

private String downloadProfile(String url) 
{ 
    String imageUrl = null; 

    try 
    { 
     String PATH = Environment.getExternalStorageDirectory().getAbsolutePath(); 
     String mimeType = getMimeType(url); 
     String fileExtension = "."+mimeType.replace("image/", ""); 

     URL u = new URL(url);    

     HttpURLConnection con = (HttpURLConnection) u.openConnection(); 
     con.setRequestMethod("GET"); 

     con.setDoInput(true); 
     con.connect(); 

     long millis=System.currentTimeMillis();  

     File file = new File(PATH); 
     file.mkdirs(); 
     File outputFile = new File(file, "_"+millis); 

     FileOutputStream f = new FileOutputStream(outputFile); 
     InputStream in = con.getInputStream(); 
     byte[] buffer = new byte[1024]; 
     int len1 = 0; 

     while ((len1 = in.read()) > 0){ 
      f.write(buffer, 0, len1); 
     } 

     imageUrl = outputFile.getAbsolutePath()+fileExtension; 

     f.close(); 
    } catch (MalformedURLException e) { 
     e.printStackTrace(); 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

    return imageUrl; 
} 
: 여기 /storage/emulated/0/_1404876264453.jpeg

내가 사진을 다운로드하고 (이 장치에 저장되는 위치의 URL을 반환) SD 카드에 저장하는 데 사용하는 코드입니다

다운로드 후 SQLite 데이터베이스에 위 URL을 삽입합니다. 그것은 잘 저장합니다. Astro 파일 관리자를 사용하여 파일이 있는지 확인했습니다. 여기

은 위의 파일 URL을 소요하고 비트 맵으로 변환을 시도한다 내 BaseAdapter의 코드입니다 :

BitmapFactory.Options options = new BitmapFactory.Options(); 
    options.inPreferredConfig = Bitmap.Config.ARGB_8888; 

    String profilePath = result_pos.get("profile_url"); // this just returns the example url 
    Bitmap bitmap = BitmapFactory.decodeFile(profilePath, options); 
    imageView.setImageBitmap(bitmap); 

로그 캣이 link.i가 그 유용 희망

07-08 23:35:17.660: E/BitmapFactory(25463): Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/_1404876264453.jpeg: open failed: ENOENT (No such file or directory) 

답변

2

확인 당신. reference link

1)create your own folder and save image name in proper way. 
2)save image path in sqlite database 
3)retrieve same path for get images. 
+0

어떻게 이미지를 백업하고 다른 장치에서 열 수 있습니까? 데이터 내보내기 중에. –

관련 문제