2013-10-25 4 views
1

중복 된 것으로 생각하지 않습니다. 글쎄, 내가 무엇을해야하는지 설명한다 .. 내 장치에 설치된 모든 응용 프로그램 목록을 가지고있다. 클릭하면 "캐시 지우기를 원합니까?"라는 대화 상자를 보여줄 필요가있다. "예"또는 물론 "아니오"로 표시됩니다. 이 자습서를 발견했습니다 : http://android-sample-code.blogspot.it/2012/01/how-to-clear-cache-data-in-android.html하지만 데이터 폴더를 삭제하는 것 같습니다. 내가 알고 싶은 것은 있습니다. 거기에 차이가 있습니까? 명확한 캐시 만위한 코드가 있고 애플리케이션의 데이터가 아닌가?android 응용 프로그램에서 캐시 지우기

코드 :

protected void onListItemClick(ListView l, View v, int position, long id) { 
     super.onListItemClick(l, v, position, id);  
     /**Clear cache*/ 
     PackageManager pm = getPackageManager(); 
     // Get all methods on the PackageManager 
     Method[] methods = pm.getClass().getDeclaredMethods(); 
     for (Method m : methods) { 
      if (m.getName().equals("freeStorage")) { 
       // Found the method I want to use 
       try { 
        long desiredFreeStorage = 8 * 1024 * 1024 * 1024; // Request for 8GB of free space 
        m.invoke(pm, desiredFreeStorage , null); 
       } catch (Exception e) { 
        // Method invocation failed. Could be a permission problem 
       } 
       break; 
      } 
     } 
    } 

답변

1

이 당신을 도움이 될 수 있습니다 :

PackageManager pm = getPackageManager(); 
// Get all methods on the PackageManager 
Method[] methods = pm.getClass().getDeclaredMethods(); 
for (Method m : methods) { 
    if (m.getName().equals("freeStorage")) { 
     // Found the method I want to use 
     try { 
      long desiredFreeStorage = 8 * 1024 * 1024 * 1024; // Request for 8GB of free space 
      m.invoke(pm, desiredFreeStorage , null); 
     } catch (Exception e) { 
      // Method invocation failed. Could be a permission problem 
     } 
     break; 
    } 
} 

그나마 잊어 허가 :

<uses-permission android:name="android.permission.CLEAR_APP_CACHE"/> 
+0

내가'onListItemClick' 방법 내부에이 코드를 작성해야? 내가 할 수 있을까? –

+0

예, Ofcourse., –

+0

내 편집 코드를 참조하십시오, 정말 작동하는지 알 수 없습니다 .. 어떻게 볼 수 있을지 모르겠는데 .. –