2

During the Rewarded video play i want to disable the back button and set a minimum waiting time . is it possible to do?On which function should i change to complete my desired functionality? here is my code

 if (mAd.isLoaded()) {
     mAd.show();

 } else {
      startActivity(new Intent(EssayActivityQstnShow2.this, Essay_Answer_Show.class));
 }

and here is Rewarded video ads handling methods

    private void loadRewardedVideoAds() {
    if (!mAd.isLoaded()) {
        mAd.loadAd(getResources().getString(R.string.rewardedvideoid), new AdRequest.Builder().build());
    }
}

@Override
public void onRewardedVideoAdLoaded() {
}

@Override
public void onRewardedVideoAdOpened() {
  //  onBackPressed();


}

@Override
public void onRewardedVideoStarted() {


 //   onBackPressed();

}

@Override
public void onRewardedVideoAdClosed() {


    startActivity(new Intent(EssayActivityQstnShow2.this, Essay_Answer_Show.class));
}

@Override
public void onRewarded(RewardItem rewardItem) {
}

@Override
public void onRewardedVideoAdLeftApplication() {
}

@Override
public void onRewardedVideoAdFailedToLoad(int i) {
    loadRewardedVideoAds();
}

@Override
public void onRewardedVideoCompleted() {
    startActivity(new Intent(EssayActivityQstnShow2.this, Essay_Answer_Show.class));
}
AskNilesh
  • 67,701
  • 16
  • 123
  • 163

2 Answers2

1

Try below code

private boolean isVideoPlaying;

@Override
public void onRewardedVideoStarted() {
    isVideoPlaying = true;
}

@Override
public void onRewardedVideoAdClosed() {
    isVideoPlaying = false;
}

and than onBackPress() check, if the video is playing or not

 @Override
public void onBackPressed() {
    if (!isVideoPlaying)
        super.onBackPressed();
}

Before implementing this, please read the policies carefully.

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Sanju Rajpal
  • 136
  • 7
0

You must override the onBackPressed callback in activity and remove line super.onBackPressed(). then if the user taps the back button the activity will not close.

If you have no access to the Essay_Answer_Show activity check can you create another activity which extends that or clone library and tries to modify activity?

SamiAzar
  • 1,260
  • 13
  • 29
  • thanks for your quick response . i have tried with a boolean variable to disable the onBackPressed method whenever the Rewarded video ads is playing ! – Mustak khadem May 13 '19 at 04:29