在我的应用中加载Admob rewardedVideo时出错

时间:2017-12-23 12:28:13

标签: android admob

我无法在我的应用中加载奖励视频 有谁可以帮助我?

这是我的代码我把吐司信息只是为了知道正在执行哪个功能

它总是给我 “广告无法加载”(在onRewardedVideoAdFailedToLoad函数中存在)
我尝试了在youtube中找到的所有东西,但仍然无法加载 广告。
我的应用加载插页式广告和横幅广告没有任何问题。

这是我的代码

package com.tech.myapplication;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
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;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        MobileAds.initialize(this,"ca-app-pub-3940256099942544~3347511713");

        mAd = MobileAds.getRewardedVideoAdInstance(this);
        mAd.setRewardedVideoAdListener(this);
        loadAdfunction();


    }

    private void loadAdfunction() {
        Toast.makeText(this,"load function",Toast.LENGTH_SHORT).show();
        AdRequest adRequest = new AdRequest.Builder().build();
        mAd.loadAd("ca-app-pub-3940256099942544/5224354917", adRequest);
    }

    @Override
    public void onRewardedVideoAdLoaded() {
        Toast.makeText(this," ad loaded successfully",Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onRewardedVideoAdOpened() {

    }

    @Override
    public void onRewardedVideoStarted() {

    }

    @Override
    public void onRewardedVideoAdClosed() {

    }

    @Override
    public void onRewarded(RewardItem rewardItem) {

    }

    @Override
    public void onRewardedVideoAdLeftApplication() {

    }

    @Override
    public void onRewardedVideoAdFailedToLoad(int i) {
        Toast.makeText(this,"Ad failed to load",Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onResume() {
        mAd.resume(this);
       super.onResume();
    }

    @Override
    public void onPause() {
    mAd.pause(this);
    super.onPause();
    }

    @Override
    public void onDestroy() {
     mAd.destroy(this);
    super.onDestroy();
    }


    public void show(View view) {
        if (mAd.isLoaded())
        {
            mAd.show();
        }
        else
        {  Toast.makeText(this,"Button clicked ad not loaded",Toast.LENGTH_SHORT).show();
            loadAdfunction();
        }

    }
}

my graddle file (app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.tech.myapplication"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile 'com.google.android.gms:play-services-ads:11.8.0'
}

1 个答案:

答案 0 :(得分:0)

请通过添加测试设备ID来检查它。它必须通过添加它来工作。对我来说,奖励视频广告在几天后开始显示。