How to Clear catch data of my application programmatically in Xamarin android mono

Viewed 8896

I had tried using the below code, I am able to get the path of the catch file but unable to delete the path or the data in that path. Below is the code I am using to do that.

public void clearApplicationData()
        {
            var tmpdir = System.IO.Path.GetTempPath();
             File applicationDirectory = new File(tmpdir);
              if (applicationDirectory != null && applicationDirectory.Exists())
            {
                //deleteFile(applicationDirectory);
                string[] fileNames = applicationDirectory.List();
                foreach (string fileName in fileNames)
                {
                    if (!fileNames.Equals("lib"))
                    {
                        deleteFile(new File(applicationDirectory, fileName));
                    }
                }
            }
        }
 public static bool deleteFile(File file)
        {
            bool deletedAll = false;
            if (file != null)
            {
                if (file.IsDirectory)
                {
                    string[] children = file.List();
                    for (int i = 0; i < children.Length; i++)
                    {
                        deletedAll = deleteFile(new File(file, children[i])) && deletedAll;
                    }
                }
                else
                {
                    file.DeleteOnExit();
                    deletedAll = file.Exists();
                }
            }

            return deletedAll;
        }

I had also added the permissions for the CLEAR_APP_CATCH, CLEAR_APP_USER_DATA Please help me doing this, I am willing to clear the complete applications cash and data and at end the I am willing to restart the application to show the login page or end application.

1 Answers
Related