

Detecting whether an AIR application has run before
source link: http://www.mikechambers.com/blog/2007/11/07/detecting-whether-an-air-application-has-run-before/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Detecting whether an AIR application has run before
Wednesday, November 7, 2007
One of the things that you might need to do when building your application is detecting whether your application has run before. This can be useful if you need to initialize settings, or perhaps prompt the user with some information.
Below is a simple example that shows how to detect whether the application has run before. Basically, it checks for the existence of a file. If it doesn’t exist, then the app hasn’t run before, if it does exist, then it means that app has run.
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="onCreationComplete()">
<mx:Script>
<![CDATA[
private const FIRST_RUN_TOKEN_FILE:File =
File.applicationStorageDirectory.resolvePath("firstrun");
private function onCreationComplete():void
{
if(FIRST_RUN_TOKEN_FILE.exists)
{
outputField.text = "This application HAS been run before";
}
else
{
var fs:FileStream = new FileStream();
fs.open(FIRST_RUN_TOKEN_FILE, FileMode.WRITE);
fs.close();
outputField.text = "This application HAS NOT been run before";
}
}
private function onResetClick():void
{
if(FIRST_RUN_TOKEN_FILE.exists)
{
FIRST_RUN_TOKEN_FILE.deleteFile();
}
}
]]>
</mx:Script>
<mx:Text top="10" left="10" right="10" id="outputField"
textAlign="center" fontSize="20"/>
<mx:Button label="Reset First Run Status"
id="resetButton" click="onResetClick()"
horizontalCenter="0" width="153" bottom="10"/>
</mx:WindowedApplication></pre>
If you need to know how many times the app has been run, then you could just write a number to the file and then increment it every-time the app runs.
One thing to keep in mind is that this is not 100% fool proof, as the user could manually delete the file. Thus you should not use this for security, serialization or trial tracking purposes.
Recommend
-
61
Another reason not to pipe from curl to bash. Detecting curl | bash serverside.
-
26
Raymond July 11th, 2019 Note to those who got here via a search engine : This is the last part of the...
-
11
ConversationWhen Bob Swan announced Intel's pragmatic approach to using external fabs, I wasn't sure if we'd see Intel actually go through with it - especially after Gelsinger was hired. But lo and behold, at least for 2023, I...
-
11
Detecting objects in a JavaFX application using YOLOv2 and DeepLearning4J A few months ago we published here the post Detecting Objects...
-
6
Detect proactively whether application’s memory is under-allocated December 17, 2021 R...
-
7
Transcript Behrens: My name is Scott Behrens. We're here to discuss modeling application risk at scale at Netflix. We're going to start with a big number, 5500 applications. For 5500 applications at Netflix, we forecasted risk...
-
3
IT run the servers, facilities run the air-con...Jack Hughes2007-10-10Data Center
-
8
This article was published as a part of the Data Science Blogathon. Introduction
-
7
Detecting Dark and Light themes in a WPF application 04/17/2023If an application support both light and dark themes, it is important to detect the current system theme and update the app...
-
6
Detecting zero-days before zero-day 09/29/2023 13 min read
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK