rewarded video ad example in libGDX(libGDX 中的奖励视频广告示例)
问题描述
我一直在寻找一个例子,但没有找到.
I've been looking for an example, but didn't found it.
我找到了一个没有 libgdx 的软件,以及一些为什么它不起作用,但应用程序也没有崩溃.
I found one without libgdx and some why it didn't work, but app also didn't crash.
public class AndroidLauncher extends AndroidApplication implements AdHandler, RewardedVideoAdListener{
...
RewardedVideoAd rewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
rewardedVideoAd.setRewardedVideoAdListener(this);
rewardedSetup();
private void rewardedSetup(){
if (!rewardedVideoAd.isLoaded()){
rewardedVideoAd.loadAd("ca-app-pub-683510441556959xxxxxxxxx", new AdRequest.Builder().build());
}
@Override
public void onRewardedVideoAdLoaded() {
if(rewardedVideoAd.isLoaded()){
rewardedVideoAd.show();
}
}
@Override
public void onRewarded(RewardItem rewardItem) {
rewarded(true);
}
}
}
它根本不显示,也许它发生在任何人身上?(我的真实代码充满了处理程序之类的东西,所以我没有把它全部写出来,我猜其他代码对这个问题的影响为0)
And it simply don't shows, maybe it happened to anyone ? (My true code is full of handlers and stuff, thus I didn't put it all, I guess other code has 0 effect on this problem)
推荐答案
private static final String APP_ID="ca-app-pub-XXXXXX~XXXXX";
private static final String AD_UNIT_ID="ca-app-pub-XXXXX/XXXXXXX";
private RewardedVideoAd mAd;
private boolean isRewardLoaded;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
MobileAds.initialize(this, APP_ID);
mAd = MobileAds.getRewardedVideoAdInstance(this);
mAd.setRewardedVideoAdListener(new RewardedVideoAdListener() {
@Override
public void onRewardedVideoAdLoaded() {
isRewardLoaded =true;
}
@Override
public void onRewardedVideoAdOpened() {
}
@Override
public void onRewardedVideoStarted() {
}
@Override
public void onRewardedVideoAdClosed() {
loadRewardedVideoAd();
}
@Override
public void onRewarded(RewardItem rewardItem) {
// call rewards method from here.
loadRewardedVideoAd(); // Load for next Reward Point
}
@Override
public void onRewardedVideoAdLeftApplication() {
}
@Override
public void onRewardedVideoAdFailedToLoad(int i) {
}
@Override
public void onRewardedVideoCompleted() {
}
});
loadRewardedVideoAd();
}
private void loadRewardedVideoAd() {
isRewardLoaded=false;
mAd.loadAd(AD_UNIT_ID, new AdRequest.Builder().build());
}
@Override
protected void onResume() {
super.onResume();
mAd.resume(this);
}
@Override
protected void onPause() {
super.onPause();
mAd.pause(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
mAd.destroy(this);
}
设置完成,需要两个方法是AdHandler
的实现,这两个方法将从core
模块调用.
set-up done, need two methods that is implementation of AdHandler
, these two methods will call from core
module.
public void showVideoAd(){
runOnUiThread(new Runnable() {
public void run() {
if (mAd.isLoaded()) {
mAd.show();
} else {
loadRewardedVideoAd();
}
}
});
}
public boolean hasVideoReward(){
return isRewardLoaded;
//return mAd.isLoaded(); // -> must be called on the main UI thread.
}
调用hasVideoReward()
,告诉你是否显示奖励面板和showVideoAd()
方法显示奖励视频.
Call hasVideoReward()
, that tell you to show reward panel or not and showVideoAd()
method show Reward Video.
希望您的 AndroidManifest.xml
文件中有这些条目
Hopefully you've these entries in your AndroidManifest.xml
file
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
这篇关于libGDX 中的奖励视频广告示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:libGDX 中的奖励视频广告示例
基础教程推荐
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01