2016-07-06 4 views
2

스크린 샷을 찍고 응용 프로그램 이름으로 저장 공간에 저장합니다. 그것은 어떤 오류도주지 않고 저장소에 사진을 저장하는 것이 아니라, 휴대 전화를 다시 시작한 후에 갤러리에 나타납니다.갤러리에 이미지 저장

public void saveQuoteImage(Bitmap quoteImage){ 
    Date now = new Date(); 
    android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now); 
    try { 
    // image naming and path to include sd card appending name you choose for file 

    String dirPath=Environment.getExternalStorageDirectory().toString()+File.separator+"quotes_king"; 

    File dirFile=new File(dirPath); 
    if(!dirFile.exists())dirFile.mkdirs(); 

    // String mPath = Environment.getExternalStorageDirectory().toString() + "/" + now + ".jpg"; 
    // create bitmap screen capture 
    File imageFile = new File(dirFile.getPath()+File.separator+ now + ".jpg"); 

    FileOutputStream outputStream = new FileOutputStream(imageFile); 
    int quality = 100; 
    quoteImage.compress(Bitmap.CompressFormat.JPEG, quality, outputStream); 

    outputStream.flush(); 
    outputStream.close(); 

    } catch (Throwable e) { 
    // Several error may come out with file handling or OOM 
    e.printStackTrace(); 
    } 
} 

내가이 누락하고 무엇 :

사진에 대한 방법을 저장 내는 다음과 같다?

감사합니다.

+0

무엇이 오류입니까? –

+0

@victorsosa 의견을 주셔서 감사합니다. 그것의 모든 오류를 제공하지하지만 저장 한 이미지를 보여주는 단지 내 휴대 전화를 다시 시작한 후. –

답변

4

당신은 당신의 파일이 존재하는지 MediaScanner에서 이야기해야합니다. 이 같은

뭔가 : android.Just에서

public final void addManually(File file) { 
     try{ 
      MediaStore.Images.Media.insertImage(mContext.getContentResolver(), 
        file.getAbsolutePath(), file.getName(), null); 
      mContext.sendBroadcast(new Intent(
        Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, 
        Uri.fromFile(file)) 
      ); 
     } catch (FileNotFoundException e) { 
      e.printStackTrace(); 
     } 
    } 
+0

로 그것을 기쁘게 할 수 있습니까? –

0

를 사용하여 미디어 스캐너는 아래의 코드를 추가합니다.

MediaScannerConnection.scanFile(this, new String[] { imagefile.toString() }, null, null); 
관련 문제