2

설정 활동에서 사용자 프로필 사진을 업데이트하려고합니다. 그 동안에도 외부 저장소의 사진을 업데이트하고 싶습니다.Android 외장 저장소가 동기화되지 않았습니다.

if (checkExternalStorage()) { 
     File filePath = context.getExternalCacheDir(); 
     File myDir = new File(filePath.getAbsolutePath() + path); 
     myDir.mkdirs(); 
     File file = new File(myDir, fileName); 
     if (file.exists()) file.delete(); 
     try { 
      FileOutputStream out = new FileOutputStream(file); 
      finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); 
      out.flush(); 
      out.close(); 
      Log.d(TAG, "File at path " + myDir.getAbsolutePath() + " was saved"); 

     } catch (Exception e) { 
      Log.e(TAG, "Unsuccessful storing image in SD card " + e.getMessage()); 
     } 

    } 

사진을 외부 저장소에 성공적으로 저장했습니다. 그런 다음 라이프 사이클 onResume에서 호출하는이 코드 줄을 사용하여 탐색 서랍의 프로필 사진을 업데이트하고 싶습니다.

File filePath = getExternalCacheDir(); 
     File myDir = new File(filePath.getAbsolutePath() + STORAGE_IMAGES_PATH + STORAGE_MY_PROFILE_PHOTO); 
     if (ImageUtils.checkExternalStorage() && myDir.exists()) { 
      Picasso.with(this).load(myDir).into(profilePhoto); 
     } 

그러나 탐색 창에있는 사진은 앱을 다시 시작해야만 업데이트됩니다. 내 장치에 저장된 이미지가있는 폴더를 열면 사진이 업데이트됩니다. 문제가 될 수있는 위치를 알고 있습니까?

+1

회원님이 아마도 캐시 된 이미지를 반환의 당시 원본 이미지를 덮어 그래서 만약 피카소가 이미지를 캐시 확실? – StuStirling

+0

해당 응용 프로그램에 대한 프로필 사진과 imageView에있는 서랍 열린 세트 이미지에 일정한 이름을 지정하십시오. –

+0

"탐색 창에서 프로필 사진을 업데이트하고 싶습니다."- 여기에는 'finalBitmap'이 사용됩니다. 디스크에서 이미지를 왜 다시로드합니까? 그 외에도'flush()'와'close()'사이에서'out.getFD(). sync()를 호출하고 캐시에 의존하기보다는 Picasa가 강제로 다시로드하도록하기 위해해야 ​​할 일이 무엇인지보십시오. – CommonsWare

답변

0

이 코드 줄로 해결했습니다.

File filePath = getExternalCacheDir(); 
       File myDir = new File(filePath.getAbsolutePath() + STORAGE_IMAGES_PATH + STORAGE_MY_PROFILE_PHOTO); 
       Picasso.with(this).invalidate(myDir);