Google AdMob集成,谷歌admob实战教程Google AdMob集成1.主要流程就不说了,官方很详细(如果要在谷歌市场上架,请一定按照规定集成,否则有下架风险)主要代码分享一下private String TAG = AdmobLog;private RewardedAd rewardedAd;@Overr......
1.主要流程就不说了,官方很详细(如果要在谷歌市场上架,请一定按照规定集成,否则有下架风险)
主要代码分享一下
private String TAG = AdmobLog;
private RewardedAd rewardedAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
rewardedAd = new RewardedAd(this,
caapppub3940256099942544/5224354917);
RewardedAdLoadCallback adLoadCallback = new RewardedAdLoadCallback() {
@Override
public void onRewardedAdLoaded() {
// Ad successfully loaded.
Log.d(TAG,加载成功);
}
@Override
public void onRewardedAdFailedToLoad(int errorCode) {
// Ad failed to load.
Log.d(TAG,加载失败);
}
};
rewardedAd.loadAd(new AdRequest.Builder().build(), adLoadCallback);
}
public void button(View view) {
if (rewardedAd.isLoaded()) {
Activity activityContext = MainActivity.this;
RewardedAdCallback adCallback = new RewardedAdCallback() {
@Override
public void onRewardedAdOpened() {
// Ad opened.
Log.d(TAG,广告打开);
}
@Override
public void onRewardedAdClosed() {
// Ad closed.
Log.d(TAG,广告关闭);
}
@Override
public void onUserEarnedReward(@NonNull RewardItem reward) {
// User earned reward.
Log.d(TAG,获得奖励);
}
@Override
public void onRewardedAdFailedToShow(int errorCode) {
// Ad failed to display.
Log.d(TAG,失败播放);
}
};
rewardedAd.show(activityContext, adCallback);
onRewardedAdClosed();
} else {
Log.d(TAG, 奖励广告尚未加载);
}
}
public RewardedAd createAndLoadRewardedAd() {
RewardedAd rewardedAd = new RewardedAd(this,
caapppub3940256099942544/5224354917);
RewardedAdLoadCallback adLoadCallback = new RewardedAdLoadCallback() {
@Override
public void onRewardedAdLoaded() {
// Ad successfully loaded.
Log.d(TAG,预加载成功);
}
@Override
public void onRewardedAdFailedToLoad(int errorCode) {
// Ad failed to load.
Log.d(TAG,预加载失败);
}
};
rewardedAd.loadAd(new AdRequest.Builder().build(), adLoadCallback);
return rewardedAd;
}
public void onRewardedAdClosed() {
this.rewardedAd = createAndLoadRewardedAd();
}
特别声明:以上文章内容仅代表作者本人观点,不代表ESG跨境电商观点或立场。如有关于作品内容、版权或其它问题请于作品发表后的30日内与ESG跨境电商联系。
二维码加载中...
使用微信扫一扫登录
使用账号密码登录
平台顾问
微信扫一扫
马上联系在线顾问
小程序
ESG跨境小程序
手机入驻更便捷
返回顶部