Android 獲取cache緩存的目錄路徑

轉發請備註原文地址:https://www.niwoxuexi.com/blog/android00/article/224.html

Android開發中,有時需要知道cache緩存的路徑。我寫了一個靜態類,供大家能參考

public class  CommonUtil {
   
   /**
    * 獲取cache路徑
    *
    * @param context
    * @return
    */
   public static String getDiskCachePath(Context context) {
      if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
         return context.getExternalCacheDir().getPath();
      } else {
         return context.getCacheDir().getPath();
      }
   }
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章