7 Replies Latest reply on Sep 20, 2013 7:50 AM by blogtom

    How to delete ApplicationStorageDirectory while uninstalling the AIR application?


      Hi Guys,


           I have developed an AIR application. I store the data files in the applicationstoragedirectory, in which I edit the data through the coding.


           The issue is:


                1, When I uninstall the application, the applicationstoragedirectory does not get deleted.


                2, When I again reinstall the application, the old data is displayed, as the applicationstoragedirectory is not deleted.


           My Question is:


                How to delete the applicationstoragedirectory when the application is uninstalled?


           Thanks a lot in advance. Awaiting with my fingers crossed for a favorable and positive reply.


           17 guys  have viewed this post but none has answered for this.... Please help!!!





      Message was edited by: TomCruise06

        • 1. Re: How to delete ApplicationStorageDirectory while uninstalling the AIR application?
          Mark Robbins 312

          AFAIK, your not going to be able to do this:


          http://webcache.googleusercontent.com/search?q=cache:hmx91vhltV0J:livedocs.adobe.com/flex/ 3/langref/flash/filesystem/File.html+adobe+air+uninstall+applicationstoragedirectory&cd=1& hl=en&ct=clnk&gl=us



          When you uninstall an AIR application, the uninstaller does not delete files that are stored    in the application storage directory.


          I know, I know.

          • 2. Re: How to delete ApplicationStorageDirectory while uninstalling the AIR application?

            Does anybody have a good workaround to this? Is this a common issue with application developers or just an Adobe AIR specific 'feature'? I can't make my own installer since this will go in Adobe's Marketplace.


            I've been trying to figure out how to tell if the app has run for the first time so I can show a EULA and my research led me down this rabbit hole...still no end in sight.

            • 3. Re: How to delete ApplicationStorageDirectory while uninstalling the AIR application?
              BhaskerChari Level 4

              Hi TomCruise06,


              I had a similar kind of problem and I had posted in the same forum, but I solved  the problem myself with a workaround explained below..






              Actually the Adobe AIR appliction doesn't delete the ApplicationStorage directory contents of the application while the application is uninstalled. So after uninstallating and reinstalling again since you again use the same installer which will have the same publisher id and the application id it will again try to write or overwrite the contents in the same Application directory which it has used previously.


              Instead if you have created a new installer by exporting the project then you will not have this problem as since this time your application will have different application id and it will try to use new folder in the Application directory instead of the old one but however this is not a workaround as you cannot send to your clients new installer each and every time they uninstall your application.


              So what you should do is you need to address this from within your code ..as you need to have a check for whether the application is uninstalled and is now being run for the first time so that you can point to ApplicationStorage directory and remove any contents if already exists.


              So for this you need to make use of Application created date...so when you write your contents to Application storage directory using shared objects you need to save the creationDate of the applicationDirectory mind you not the applicationStorageDirectory. Why because each timeyou uninstall your application your applicationDirectory get deleted which resides in the program file but applicationStorageDirectory will not be deleted.


              This code you need to write when you are saving your contents using the SharedObject in the ApplicationStorage Directory.

              var dir:File = File.applicationDirectory;
              locationPrefsObj.data.appCreatedDate = dir.creationDate.toString();

              And you should now have a check in the creationComplete event of the Application...


              private function init():void
                // This function checks weather the application is installed and is launched for the first time then it will ask the user for login
                // i.e; to enter locationId and if it is not then it will login automatically and display the main screen
                private function checkAutoLogin():void
                  var locationPrefsObj:SharedObject = SharedObject.getLocal("PrefsObj");   

                   var dir:File = File.applicationDirectory;
                   var appCreatedDate:String = dir.creationDate.toString();
                   if(locationPrefsObj.data.appCreatedDate == appCreatedDate)
                    //This means that the application is not reinstalled and so you need not delete the applicationStorageDirectory contents

                    //Write your logic


                   //So here you will come to know that your application has been reinstalled and so you need to delete the applicationStorageDirectory contents.
                    trace("locationPrefsObj.data.appCreatedDate=" + locationPrefsObj.data.appCreatedDate);
                    trace("curr_appCreatedDate=" + appCreatedDate);

                 // This function clears or deletes the applicationStorageDirectory contents

                private function clearPrivateData():void
                 var appDataStorageDir:File = File.applicationStorageDirectory;



              Hope this is clear and if you have any doubt please let me know.




              • 4. Re: How to delete ApplicationStorageDirectory while uninstalling the AIR application?

                Hello Bhasker...


                U Had given right solution for deleting Shared Object. When application uninstall it will not delete store Shared Object of application. Becuase of that after new installation of application contents of shared objects are fetched on the application which should not happen.


                Solution for that it is very good on creationComplete() compare the creation date of application installation with application directory creation date if it is same then no new installation of application if there is any mismatch between dates then it is assum that application is newly installed and in that simply cleared the data content shared Object.


                var sObject: SharedObject = SharedObject.getLocal(Model.getInstance().shared_objectName);
                            if(sObject.data.appCreatedDate != appCreatedDate || sObject.data.appCreatedHours != appCreatedHours || sObject.data.appCreatedMinutes != appCreatedMinutes )
                                for (var i in sObject.data) {
                                    delete sObject.data[i];


                Thanks Bhasker for heping me for getting propper solution...

                • 5. Re: How to delete ApplicationStorageDirectory while uninstalling the AIR application?
                  Flex__RIA_Developer Level 1

                  Thanks Bhasker


                  I did googling for this issue but only got solution from u...

                  • 6. Re: How to delete ApplicationStorageDirectory while uninstalling the AIR application?



                    But what if the user does not start the application after installing. The applicationStorageDirectory is only created when you start the app for the first time isn't it?




                    • 7. Re: How to delete ApplicationStorageDirectory while uninstalling the AIR application?
                      blogtom Level 1

                      You could simply delete everything on the apps 1st run (when it's first launched after installation) by using this: