Google AdMob集成,google官方adb工具包Google AdMob集成1.主要流程就不說了,官方很詳細(如果要在谷歌市場上架,請一定按照規定集成,否則有下架風險)主要代碼分享一下private String TAG = AdmobLog;private RewardedAd rewardedAd;@Ov......
1.主要流程就不說了,官方很詳細(如果要在谷歌市場上架,請一定按照規定集成,否則有下架風險)
主要代碼分享一下
private String TAG = AdmobLog;
private RewardedAd rewardedAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activitymain);
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跨境小程序
手機入駐更便捷
返回頂部