0
我試圖開發一個Android應用程序,可以列出所有應用程序的緩存大小和清理緩存,清理緩存工作正常,但列出所有緩存的應用程序是問題。所以我試圖檢查應用程序包是否有緩存文件夾,如果它退出,然後我試圖檢查緩存文件夾是否爲空,但我得到強制關閉,我也使用AsyncTask,但獲得力關閉,我檢查了我的代碼爲普通的java代碼,它的工作,不知道有什麼問題,請指導我,在此先感謝。如何檢查在android中是否有子文件夾?
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AsyncTask<Void, Void, Void>()
{
@Override
protected void onPreExecute()
{
pd = ProgressDialog.show(MainActivity.this, "Loading..",
"Please Wait", true, false);
}//End of onPreExecute method
@Override
protected Void doInBackground(Void... params)
{
File file = new File("/data/data/com.android.browser/cache");
if(file.isDirectory()){
if(file.list().length>0){
System.out.println("Directory is not empty!");
}else{
System.out.println("Directory is empty!");
}
}else{
System.out.println("This is not a directory");
}
return null;
}//End of doInBackground method
@Override
protected void onPostExecute(Void result)
{
pd.dismiss();
}//End of onPostExecute method
}.execute((Void[]) null);
}
});
AsyncTask沒有問題我用其他東西檢查了代碼,沒關係。請幫我解決這個謎題。
不,不工作@No_Rulz感謝您的時間。 –