2011-08-06 14 views
0

ベースクラスを拡張したimageAdapterを使用してイメージをダウンロードしています。私は、彼らがキャッシュ内にあるかどうかを確認するためにテストするのはここのキャッシュ に格納Imがあるキャッシュディレクトリをテストするには?

  URI imageUri = null; 

      //Setting the Uri of aURL to imageUri. 
      try { 
      imageUri = aURL.toURI(); 

      } catch (URISyntaxException e1) { 
      // TODO Auto-generated catch block 
       e1.printStackTrace(); 
         } 



       //Testing to see if images are already in cache, if not then we load the images from the web and save them to the cache. 
      if (new File(new File(myContext.getCacheDir(), "thumbnails"), "" + imageUri.hashCode()).exists()) 
          { 

     Log.v("Loader", "File exists in cache. Now pulling from the cache"); 

     String cachFile = myContext.getCacheDir() +"/thumbnails/"+imageUri.hashCode(); 
     FileInputStream fis; 

私の質問私は、アプリケーション内の別の方法では、このキャッシュディレクトリ」サムネイルをテストする方法を教えてください。

答えて

1

することですファイルがキャッシュディレクトリ内にあるかどうかというテスト、ちょうどあなたのケースでは

File f = new File("<path_to_your_file>"); 
f.exists(); //TRUE if the file exists, FALSE otherwise. 

を使用し、あなたがmyContext.getCacheDirので、他の方法で同じコードを使用することができます()は、アプリケーション全体で同じディレクトリを返します。

しかし、他の方法では、まだテストするimageUriを知る必要があります。

+0

これは正しいことです、私は特定のimageUriをテストしたいのですが、どうすれば別の方法でこれをテストできますか? –

+0

上記のコードでキャッシュの中に入れた画像をテストしたいと思います。キャッシュが存在する期間だけではありません。 –