Google AdMob集成,谷歌admob實(shí)戰(zhàn)教程Google AdMob集成1.主要流程就不說了,官方很詳細(xì)(如果要在谷歌市場上架,請一定按照規(guī)定集成,否則有下架風(fēng)險(xiǎn))主要代碼分享一下private String TAG = AdmobLog;private RewardedAd rewardedAd;@Overr......
1.主要流程就不說了,官方很詳細(xì)(如果要在谷歌市場上架,請一定按照規(guī)定集成,否則有下架風(fēng)險(xiǎn))
主要代碼分享一下
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,廣告關(guān)閉);
}
@Override
public void onUserEarnedReward(@NonNull RewardItem reward) {
// User earned reward.
Log.d(TAG,獲得獎勵(lì));
}
@Override
public void onRewardedAdFailedToShow(int errorCode) {
// Ad failed to display.
Log.d(TAG,失敗播放);
}
};
rewardedAd.show(activityContext, adCallback);
onRewardedAdClosed();
} else {
Log.d(TAG, 獎勵(lì)廣告尚未加載);
}
}
public RewardedAd createAndLoadRewardedAd() {
RewardedAd rewardedAd = new RewardedAd(this,
caapppub3940256099942544/5224354917);
RewardedAdLoadCallback adLoadCallback = new RewardedAdLoadCallback() {
@Override
public void onRewardedAdLoaded() {
// Ad successfully loaded.
Log.d(TAG,預(yù)加載成功);
}
@Override
public void onRewardedAdFailedToLoad(int errorCode) {
// Ad failed to load.
Log.d(TAG,預(yù)加載失敗);
}
};
rewardedAd.loadAd(new AdRequest.Builder().build(), adLoadCallback);
return rewardedAd;
}
public void onRewardedAdClosed() {
this.rewardedAd = createAndLoadRewardedAd();
}
特別聲明:以上文章內(nèi)容僅代表作者本人觀點(diǎn),不代表ESG跨境電商觀點(diǎn)或立場。如有關(guān)于作品內(nèi)容、版權(quán)或其它問題請于作品發(fā)表后的30日內(nèi)與ESG跨境電商聯(lián)系。
二維碼加載中...
使用微信掃一掃登錄
使用賬號密碼登錄
平臺顧問
微信掃一掃
馬上聯(lián)系在線顧問
小程序
ESG跨境小程序
手機(jī)入駐更便捷
返回頂部