기록용
private AdView mAdView; //배너광고
private InterstitialAd mInterstitialAd; //전면광고
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 광고 초기화
MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
//배너
AdView adView = new AdView(this);
adView.setAdSize(AdSize.SMART_BANNER);
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
//전면
MobileAds.initialize(this,
"ca-app-pub-3940256099942544~3347511713");
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
}
@Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
}
@Override
public void onAdOpened() {
// Code to be executed when the ad is displayed.
}
@Override
public void onAdClicked() {
// Code to be executed when the user clicks on an ad.
}
@Override
public void onAdLeftApplication() {
// Code to be executed when the user has left the app.
}
@Override
public void onAdClosed() {
// Code to be executed when the interstitial ad is closed.
mInterstitialAd.loadAd(new AdRequest.Builder().build());
}
});
}
}
'프로그래밍' 카테고리의 다른 글
안드로이드 스튜디오 - 빌드 하는 방법(플레이 스토어에 올리기) (0) | 2021.01.06 |
---|---|
안드로이드 - 쉽고 간단하게 타이틀바 없애기 (0) | 2020.12.30 |
안드로이드 - 배너광고 소스 (Android Banner AD Source) (0) | 2020.12.28 |
스프링 최신버전 확인 Index of release/org/springframework/spring (0) | 2020.12.27 |
방문자 카운터 쉽게 코딩하기 (0) | 2020.12.27 |
댓글