2010-08-31 50 views

回答

2

試試這個

public static void trimCache(Context context) { 
     try { 
      File dir = context.getCacheDir(); 
      if (dir != null && dir.isDirectory()) { 
       deleteDir(dir); 

      } 
     } catch (Exception e) { 
      // TODO: handle exception 
     } 

    } 

    public static boolean deleteDir(File dir) { 
     if (dir!=null && dir.isDirectory()) { 
      String[] children = dir.list(); 
      for (int i = 0; i < children.length; i++) { 
       boolean success = deleteDir(new File(dir, children[i])); 
       if (!success) { 
        return false; 
       } 
      } 
     } 

     // The directory is now empty so delete it 
     return dir.delete(); 
    } 

也加入這一行你menifest.xml

<uses-permission android:name="android.permission.CLEAR_APP_CACHE"></uses-permission> 
相關問題