我可以在卸载时删除特定于应用程序的SD卡数据吗?

时间:2012-08-23 05:28:35

标签: android

在以编程方式卸载应用程序时,是否可以删除特定于应用程序的SD卡数据?

1 个答案:

答案 0 :(得分:0)

使用此

@Override
    protected void onDestroy()
    {
        super.onDestroy();
        File checkFile = new File("/sdcard/Accentra/");//getting the control of sdcard files
        deleteDir(checkFile);
    }

    //Deleting the temperary folder and the file created in the sdcard
    public static boolean deleteDir(File dir) 
    {
        if (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();
    }