Reputation: 61
i tried to create admob rewarded video for my application it worked perfectly on test app but it did't work on real one.is there any rules that admob put and i didn't know .dose it need time until the real id get activated
this are the codes that i tired and there is no error in it but the think is it work on test id but not real one package com.example.median1.helper;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.reward.RewardItem;
import com.google.android.gms.ads.reward.RewardedVideoAd;
import com.google.android.gms.ads.reward.RewardedVideoAdListener;
public class MainActivity extends AppCompatActivity implements RewardedVideoAdListener {
private RewardedVideoAd mAd;
private TextView mText;
private Button Start;
public int credit=0;
public int sum;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mText=(TextView)findViewById(R.id.textView);
MobileAds.initialize(getApplicationContext(),"");
mAd=MobileAds.getRewardedVideoAdInstance(this);
mAd.setRewardedVideoAdListener(this);
loadRewardVideoAd();
}
private void loadRewardVideoAd(){
if(!mAd.isLoaded()){
mAd.loadAd("",new AdRequest.Builder().build());
}else {
Toast.makeText(this, "Please try again later", Toast.LENGTH_SHORT).show();
}
}
public void startvideoadd(View view){
if(mAd.isLoaded()){
mAd.show();
}
}
@Override
public void onRewardedVideoAdLoaded() {
}
@Override
public void onRewardedVideoAdOpened() {
}
@Override
public void onRewardedVideoStarted() {
}
@Override
public void onRewardedVideoAdClosed() {
loadRewardVideoAd();
}
@Override
public void onRewarded(RewardItem rewardItem) {
mText.setText("now you can start");
sum=credit+10;
}
@Override
public void onRewardedVideoAdLeftApplication() {
}
@Override
public void onRewardedVideoAdFailedToLoad(int i) {
}
@Override
protected void onPause() {
mAd.pause(this);
super.onPause();
}
@Override
protected void onResume() {
mAd.resume(this);
super.onResume();
}
@Override
protected void onDestroy() {
mAd.destroy(this);
super.onDestroy();
}
public void start(View view){
if(sum==10){
Intent Nextpage=new Intent(MainActivity.this,Helper.class);
startActivity(Nextpage);
}else {
Toast.makeText(this, "Please watch a video", Toast.LENGTH_LONG).show();
}
}
}
Upvotes: 1
Views: 680
Reputation: 5840
It could be a matter of no fill error which means that google could not supply a real rewarded ad for your specific time of request (it depends mainly on Geo and advertising campaigns running In this Geo)
You should simply check the error code returned in the ad failed event:
@Override
public void onRewardedVideoAdFailedToLoad(int i) {
// check the value of I and you will know the failure reason
}
Upvotes: 3