1

블로그 게시물이 RSS 피드에서 가져 오는 Android 앱을 개발했습니다.
이 게시물에는 블로그 게시물의 제목과 이미지가 들어 있습니다.
나는 다음과 같은 코드를 사용하여 이미지 캐시를 저장하고 :내부 메모리의 파일 캐시 저장

public class FileCache { 

private File cacheDir; 

public FileCache(Context context) { 
    // Find the dir to save cached images 
    if (android.os.Environment.getExternalStorageState().equals(
      android.os.Environment.MEDIA_MOUNTED)) 
     cacheDir = new File(
       android.os.Environment.getExternalStorageDirectory(), 
       "LazyList"); 
    else 
     cacheDir = context.getCacheDir(); 
    if (!cacheDir.exists()) 
     cacheDir.mkdirs(); 
} 

public File getFile(String url) { 
    // I identify images by hashcode. Not a perfect solution, good for the 
    // demo. 
    String filename = String.valueOf(url.hashCode()); 
    // Another possible solution (thanks to grantland) 
    // String filename = URLEncoder.encode(url); 
    File f = new File(cacheDir, filename); 
    return f; 

} 

public void clear() { 
    File[] files = cacheDir.listFiles(); 
    if (files == null) 
     return; 
    for (File f : files) 
     f.delete(); 
} 

} 

을하지만 현재의 메모리 카드가
내가 캐시, 즉 외부 저장/내부 저장 중 저장을위한 두 옵션을 할 때 문제가 단지 캐시에 저장되어

답변

0

그냥 getExternalStorage 상태로 확인하고 SD 카드에만 캐시 용 디렉토리를 만들었습니다 ... 아래 조건을 사용하려고 시도하십시오.

final String cachePath = 
     Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || 
       !isExternalStorageRemovable() ? getExternalCacheDir(context).getPath() : 
         context.getCacheDir().getPath(); 

return new File(cachePath + File.separator + uniqueName); 
관련 문제