Flex mobile:如何知道它是第一次运行应用程序

时间:2012-04-28 12:31:09

标签: flex mobile

我用谷歌搜索但没有找到Flex手机的帖子.. 我想要的只是当用户第一次使用应用程序时显示来自TabbedViewNavigatorApplication的用户协议弹出

var agreementView: UserAgreement = new UserAgreement();
PopUpManager.addPopUp(agreementView, this,true);
PopUpManager.centerPopUp(agreementView);

但也许更晚。

请帮助..

2 个答案:

答案 0 :(得分:1)

我在桌面播放应用中做了什么; 我想这也适用于移动应用程序。

确保您具有写入权限; 打开yourproject-app.mxml向下滚动到文档的末尾。在该部分中,取消注释以下权限:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

现在您可以创建文件,例如sqlite数据库。

在applicationcomplete上调用函数checkFirstRun:

    //  functions to check if the application is run for the first time (also after updates)
    // so important structural changes can be made here.
    public var file:File;
    public var currentVersion:Number;   
    private function checkFirstRun():void
    {
    //get the current application version.
    currentVersion=getApplicationVersion();

        //get versionfile
        file = File.applicationStorageDirectory;
        file= file.resolvePath("Preferences/version.txt");
        if(file.exists)
        {
            checkVersion();
        }
        else
        {
            firstRun(); // create the version file.
        }
    }

        public function getApplicationVersion():Number
        {
            var appXML:XML = NativeApplication.nativeApplication.applicationDescriptor;
            var ns:Namespace = appXML.namespace();
            var versionnumber:Number =Number(appXML.ns::versionNumber);
            return versionnumber;       
        }
private function checkVersion():void
{
    var stream:FileStream= new FileStream();
    stream.open(file,FileMode.READ);
    var prevVersion:String = stream.readUTFBytes(stream.bytesAvailable);
    stream.close();
    if(Number(prevVersion)<currentVersion)
    {
        // if the versionnumber inside the file is older than the current version we go and run important code.
        // like alternating the structure of tables inside the sqlite database file.
        runImportantCode();

        //after running the important code, we set the version to the currentversion. 
        saveFile(currentVersion);
    }   
}
private function firstRun():void
{
    // at the first time, we set the file version to 0, so the important code will be executed. 
    var firstVersion:Number=0;
    saveFile(firstVersion);

    // we also run the checkversion so important code is run right after installing an update
    //(and the version file doesn't exist before the update).
    checkFirstRun();
}

private function saveFile(currentVersion:Number):void
{
    var stream:FileStream=new FileStream();
    stream.open(file,FileMode.WRITE);
    stream.writeUTFBytes(String(currentVersion));
    stream.close();
}


private function runImportantCode():void
{
    // here goes important code.
    // make sure you check if the important change previously has been made or not, because this code is run after each update.

}

希望这会有所帮助。 Greets,J。

答案 1 :(得分:0)

您需要存储一些用户是否同意该协议。如果他们没有达成一致,那么就表明。

执行此操作的一种方法是将值存储在共享对象中。另一种方法是使用远程服务并将这些数据存储在中央存储库中。我假设你想要第二个;因此,您可以针对使用您的应用的用户数进行某种形式的跟踪。