如何限制用户使用我的Flatter android应用程序的服务期限?瞧

如何限制用户使用我的Flatter android应用程序的服务期限?瞧,android,firebase,flutter,dart,google-play,Android,Firebase,Flutter,Dart,Google Play,我正在构建一个视频编辑应用程序。。。 我想为第一次使用应用程序提供一些免费分钟。用户可以编辑视频,直到完成免费分钟。 这些分钟是根据正在编辑的视频的持续时间计算的 之后,他们必须购买任何持续时间的视频 如何限制用户在空闲时间前使用一些 到目前为止,我的应用程序中没有使用任何在线服务。这台设备一切正常。 有没有办法在离线状态下实现。? 如果不可能。。 我能做些什么来解决它 我不是以英语为母语的人。。 试着去理解……:) 这是一个计时器,在没有剩余时间时触发。 它完全脱机工作。 这是在任何其他通常声

我正在构建一个视频编辑应用程序。。。 我想为第一次使用应用程序提供一些免费分钟。用户可以编辑视频,直到完成免费分钟。 这些分钟是根据正在编辑的视频的持续时间计算的

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

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

到目前为止,我的应用程序中没有使用任何在线服务。这台设备一切正常。 有没有办法在离线状态下实现。? 如果不可能。。 我能做些什么来解决它

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

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

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

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”保存到设备中,并在应用程序启动时加载它。

这对您有帮助吗?
@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();

}