【问题标题】:limit reward button press to once an hour将奖励按钮按下限制为每小时一次
【发布时间】:2017-11-06 17:11:28
【问题描述】:

我在我的应用程序中设置了奖励广告系统。目前,每次我按下奖励按钮时,都会显示奖励广告。但我想将其限制为每小时单击一次。

这是我的按钮 onclick,位于我的广告加载方法中。我已经这样做了,因为在某些互联网连接速度较慢的设备上,在人们按下按钮之前广告没有加载。

 @Override
        public void onRewardedVideoAdLoaded() {
            Toast.makeText(Competition.this, "Advert loaded please click the Reward button to continue", Toast.LENGTH_LONG).show();
            btn1 = (Button) findViewById(R.id.btncomp_ok);
            btn1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    showRewardedVideo();
                }
            });

        }

我还有一个连接到我的应用的 Firebase 数据库。这会计算广告被观看到最后的次数。

 ref.child("Reward").child(Userid).child("screenname").setValue(Username);
    ref.child("Reward").child(Userid).child("watched").runTransaction(new Transaction.Handler() {
        @Override
        public Transaction.Result doTransaction(MutableData mutableData) {

            if (mutableData.getValue() == null) {
                mutableData.setValue(1);
            } else {
                int count = mutableData.getValue(Integer.class);
                mutableData.setValue(count + 1);
            }
            ;

            return Transaction.success(mutableData);


        }

【问题讨论】:

    标签: java android timer counter limit


    【解决方案1】:

    您可以检查他们最后一次点击的时间,并确保在调用 showRecordedVideo() 之前已经过了一个小时。 lastClickTime 可以存储在 db 或 sharedpreferences 中。

    @Override
    public void onRewardedVideoAdLoaded() {
        static int ONEHOUR = 60 * 60 * 1000;
        Toast.makeText(Competition.this, "Advert loaded please click the Reward button to continue", Toast.LENGTH_LONG).show();
        btn1 = (Button) findViewById(R.id.btncomp_ok);
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (System.currentTimeMillis() >= lastClickTime + ONEHOUR) {
                    showRewardedVideo();
                }
            }
        });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-21
      • 1970-01-01
      • 1970-01-01
      • 2016-10-02
      • 1970-01-01
      相关资源
      最近更新 更多