【问题标题】:How to limit user to use limite duration of service of my flutter android application? Lo如何限制用户使用我的颤振 android 应用程序的有限服务期限?罗
【发布时间】:2021-08-16 09:22:22
【问题描述】:

我正在构建一个用于视频编辑的应用程序... 我想为第一次使用 app 提供一些免费时间。用户可以编辑视频,直到完成免费分钟。 这些分钟数基于正在编辑的视频的时长..

之后,他们必须购买任何持续时间的视频..?

如何限制用户在空闲时间之前使用一些?

到目前为止,我还没有在我的应用程序中使用任何在线服务。一切都在设备上运行。 有什么方法可以离线实现它。? 如果不可能.. 我能做些什么来解决它..?

我不是以英语为母语的人.. 试着理解... :)

【问题讨论】:

    标签: android firebase flutter dart google-play


    【解决方案1】:

    这是一个计时器,将在没有时间时触发。 它完全离线工作。 这在您通常声明变量的任何其他方法之外的类中:(请注意,您可以以毫秒为单位设置所需的时间。我选择了 10000 毫秒,例如 10 秒)

    private CountDownTimer timer;
    private long secondsLeft = 10000; // how much milliseconds of 
    // free time you want to have
    

    // 这就是你想要开始时间的地方。

    timer = new CountDownTimer(secondsLeft, 1000) {  
        public void onTick(long millisUntilFinished) {
            secondsLeft = millisUntilFinished/1000;
        }
    
        public void onFinish() {
            // The time is up! User has spent the time
        }  
    }.start();
    

    然后添加这些(或者如果您已经拥有这些方法,则将其中的代码添加到您的方法中。

    @Override
    protected void onPause() {
        super.onPause();
        timer.cancel();
    }
    
    @Override
    protected void onResume() {
        super.onResume();
        timer = new CountDownTimer(secondsLeft, 1000) {
            public void onTick(long millisUntilFinished) {
                secondsLeft = millisUntilFinished/1000;
            }
    
            public void onFinish() {
                // The time is up! The user has used the app for your amount of time
            }
        }.start();
    
    }
    

    注意:要让它在应用重启或手机重启后仍然有效,您必须将“secondsLeft”保存到您的设备并在应用启动时加载它。

    【讨论】:

    • 这对您有帮助吗?
    猜你喜欢
    • 2023-03-24
    • 1970-01-01
    • 2012-09-16
    • 1970-01-01
    • 2012-08-15
    • 1970-01-01
    • 1970-01-01
    • 2021-04-26
    • 1970-01-01
    相关资源
    最近更新 更多