Admob android:奖励视频有时不显示

时间:2017-05-18 23:42:49

标签: android admob rewardedvideoad

我想在我的Android应用程序上实现奖励视频,我第一次点击显示视频,工作得很好,但在那之后第二次或第三次点击再次显示它,它不起作用,并抛出日志:

W/MessageQueue: Handler (com.google.android.gms.ads.exoplayer2.upstream.u) {1e5487c} sending message to a Handler on a dead thread
                                                                     java.lang.IllegalStateException: Handler (com.google.android.gms.ads.exoplayer2.upstream.u) {1e5487c} sending message to a Handler on a dead thread
                                                                         at android.os.MessageQueue.enqueueMessage(MessageQueue.java:543)
                                                                         at android.os.Handler.enqueueMessage(Handler.java:631)
                                                                         at android.os.Handler.sendMessageAtTime(Handler.java:600)
                                                                         at android.os.Handler.sendMessageDelayed(Handler.java:570)
                                                                         at android.os.Handler.sendEmptyMessageDelayed(Handler.java:534)
                                                                         at android.os.Handler.sendEmptyMessage(Handler.java:519)
                                                                         at com.google.android.gms.ads.exoplayer2.upstream.u.run(:com.google.android.gms.DynamiteModulesA:212)
                                                                         at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
                                                                         at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                         at java.lang.Thread.run(Thread.java:818)


Could not show rewarded video ad from adapter.
                                                          java.lang.NullPointerException: Attempt to read from field 'com.google.android.gms.ads.internal.client.bq ip.a' on a null object reference
                                                              at com.google.ads.mediation.a.g(:com.google.android.gms.DynamiteModulesA:17227)
                                                              at com.google.android.gms.ads.internal.mediation.client.u.f(:com.google.android.gms.DynamiteModulesA:436)
                                                              at com.google.android.gms.ads.internal.reward.b.a(:com.google.android.gms.DynamiteModulesA:1314)
                                                              at com.google.android.gms.ads.internal.reward.client.e.onTransact(:com.google.android.gms.DynamiteModulesA:65)
                                                              at android.os.Binder.transact(Binder.java:387)
                                                              at com.google.android.gms.internal.zznu$zza$zza.show(Unknown Source)
                                                              at com.google.android.gms.internal.zzoc.show(Unknown Source)
                                                              at com.reperfection.monopoly.MainActivity$1.onClick(MainActivity.java:70)
                                                              at android.view.View.performClick(View.java:5702)
                                                              at android.view.View$PerformClick.run(View.java:22546)
                                                              at android.os.Handler.handleCallback(Handler.java:739)
                                                              at android.os.Handler.dispatchMessage(Handler.java:95)
                                                              at android.os.Looper.loop(Looper.java:158)
                                                              at android.app.ActivityThread.main(ActivityThread.java:7237)
                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Could not call showVideo.
                                                          android.os.RemoteException
                                                              at com.google.android.gms.ads.internal.mediation.client.u.f(:com.google.android.gms.DynamiteModulesA:439)
                                                              at com.google.android.gms.ads.internal.reward.b.a(:com.google.android.gms.DynamiteModulesA:1314)
                                                              at com.google.android.gms.ads.internal.reward.client.e.onTransact(:com.google.android.gms.DynamiteModulesA:65)
                                                              at android.os.Binder.transact(Binder.java:387)
                                                              at com.google.android.gms.internal.zznu$zza$zza.show(Unknown Source)
                                                              at com.google.android.gms.internal.zzoc.show(Unknown Source)
                                                              at com.reperfection.monopoly.MainActivity$1.onClick(MainActivity.java:70)
                                                              at android.view.View.performClick(View.java:5702)
                                                              at android.view.View$PerformClick.run(View.java:22546)
                                                              at android.os.Handler.handleCallback(Handler.java:739)
                                                              at android.os.Handler.dispatchMessage(Handler.java:95)
                                                              at android.os.Looper.loop(Looper.java:158)
                                                              at android.app.ActivityThread.main(ActivityThread.java:7237)
                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

这是我的代码:

public class MainActivity extends AppCompatActivity implements RewardedVideoAdListener {

TextView counterTV;
ImageView clickerBoard;
int counter;
int step = 1;
RelativeLayout parentRl;
LinearLayout ln1;
LinearLayout ln2;
private RewardedVideoAd mAd;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left);
    setContentView(R.layout.activity_main);

    counterTV = (TextView) findViewById(R.id.counter);
    parentRl = (RelativeLayout) findViewById(R.id.parentRl);
    clickerBoard = (ImageView) findViewById(R.id.clickerBoard);
    ln1 = (LinearLayout) findViewById(R.id.ln1);
    ln2 = (LinearLayout) findViewById(R.id.ln2);

    // Init rewarded video
    mAd = MobileAds.getRewardedVideoAdInstance(this);
    mAd.setRewardedVideoAdListener(this);
    loadRewardedVideoAd();

    ln1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mAd.isLoaded()) {
                mAd.show();
            }
        }
    });
}

private void loadRewardedVideoAd() {
    mAd.loadAd("ca-app-pub-3940256099942544/5224354917", new AdRequest.Builder().build());
}
@Override
public void onRewarded(RewardItem reward) {
    Toast.makeText(this, "onRewarded! currency: " + reward.getType() + "  amount: " +
            reward.getAmount(), Toast.LENGTH_SHORT).show();
    // Reward the user.
}

// The following listener methods are optional.
@Override
public void onRewardedVideoAdLeftApplication() {
    Toast.makeText(this, "onRewardedVideoAdLeftApplication",
            Toast.LENGTH_SHORT).show();
}

@Override
public void onRewardedVideoAdClosed() {
    Toast.makeText(this, "onRewardedVideoAdClosed", Toast.LENGTH_SHORT).show();
    loadRewardedVideoAd();
}

@Override
public void onRewardedVideoAdFailedToLoad(int errorCode) {
    Toast.makeText(this, "onRewardedVideoAdFailedToLoad", Toast.LENGTH_SHORT).show();
}

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

@Override
public void onRewardedVideoAdOpened() {
    Toast.makeText(this, "onRewardedVideoAdOpened", Toast.LENGTH_SHORT).show();
}

@Override
public void onRewardedVideoStarted() {
    Toast.makeText(this, "onRewardedVideoStarted", 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();
}}

你能帮忙弄清楚出了什么问题吗? 感谢

6 个答案:

答案 0 :(得分:2)

<强>解

我遇到同样的问题并期待official example我发现他们没有打电话

RewardedVideoAd.destroy(Context)

虽然他们告诉他们在official tutorial中打电话。所以在删除后,它就可以了。

答案 1 :(得分:0)

关于manual,您似乎需要重新加载视频: 覆盖此方法

onRewardedVideoAdClosed() {
loadRewardedVideoAd();
}

答案 2 :(得分:0)

如果您要求从admob获取广告,当您已经获得另一个关于从admob获取广告的视频请求时,您提出的第一个请求将返回广告并且您决定显示()广告,您是获取无法显示来自适配器的奖励视频广告。错误。

我认为这是关于单身的某种方式。您提出的第二个请求会在第一个请求中中断。这会让人感到困惑,因为您可以创建com.google.android.gms.ads.reward.RewardedVideoAdListener()的多个实例。在我的情况下,如果您已经等待第一个请求,我们必须阻止第二个请求才能使用。

答案 3 :(得分:0)

我遇到了完全相同的问题,经过几天的调查后我找到了解决方案。

您必须非常小心RewardedVideoAd生命周期。 就我而言,我将活动生命周期与此对象联系起来。但是我明白,向onResume()对象调用RewardedVideoAd将会重新启动&#34;重新启动&#34;它,所以即使您之前加载了广告,也需要重新加载一个广告。

正如您可能在其他主题中找到的那样,即使SDK允许,也不要尝试同时加载广告。如果没有预先加载广告,或者刚刚调用onResume() RewardedVideoAd对象,请确保在您的广告系列中加载广告

不要犹豫,记录您的RewardedVideoAd回调方法,以帮助您了解和优化广告加载流程。

答案 4 :(得分:0)

我正在放置一个admob视频,当你进入活动时执行该视频,我在第二次进入活动时遇到了同样的问题。在我的情况下,我放了一个可执行循环来启动视频已经加载。

if (mRewardedVideoAd.isLoaded()) {
        mRewardedVideoAd.show();
    }else{
        loadRewardedVideoAd();
    }

这是我所有代码的一部分

private boolean started = false;
private Handler handler = new Handler();

private void initializeAdMob() {
    mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
    mRewardedVideoAd.setRewardedVideoAdListener(this);
    loadRewardedVideoAd();
}

private void loadRewardedVideoAd() {
    if (!mRewardedVideoAd.isLoaded()) {
        mRewardedVideoAd.loadAd(getString(R.string.id_block_activity), new AdRequest.Builder().build());
    }
}

private void showRewardedVideoAd() {
    if (BaseInteractor.isNetworkAvailable(this)) {
        showProgressBar(true);
        start();
    }
}

private Runnable runnable = new Runnable() {
    @Override
    public void run() {
        if (mRewardedVideoAd.isLoaded()) {
            mRewardedVideoAd.show();
        }else{
            loadRewardedVideoAd();
        }
        if (started) {
            start();
        }
    }
};

public void stop() {
    started = false;
    handler.removeCallbacks(runnable);
}

public void start() {
    started = true;
    handler.postDelayed(runnable, 2000);
}

最后我在

中停止了runnable
@Override
public void onRewardedVideoAdOpened() {
    showProgressBar(false);
    stop();
}

我希望这会对你有所帮助。

答案 5 :(得分:0)

根据Google文档(link)获取新的奖励视频广告。

RewardedAd是一次性使用的对象。这意味着,一旦显示了奖励广告,该对象就无法用于加载其他广告。要请求另一个奖励广告,您需要创建一个新的RewardedAd对象。

因此,如果您需要第二个广告,则需要处理现有的rewardedAd对象并创建一个新对象。 您可以这样做:

rewardedAd=null;
rewardedAd = new RewardedAd(this,"ca-app-pub-3940256099942544/5224354917");