기록용입니다. 참고하실 분들은 참고하세요.
하다가 모르는거 있으면 댓글 달아주세요!
웹뷰에 배너광고 넣기.
배너 광고는 하단에 배치하였음.
developers.google.com/admob/android/interstitial?hl=ko
-build.gradle(Module)
implementation 'com.google.android.gms:play-services-ads:19.6.0'
-AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<meta-data
android:name="com.google.android.gms.ads.AD_MANAGER_APP"
android:value="true" />
-MainActivity
public class MainActivity extends AppCompatActivity {
private AdView mAdView;
@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);
mAdView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
}
@Override
public void onAdFailedToLoad(LoadAdError adError) {
// Code to be executed when an ad request fails.
}
@Override
public void onAdOpened() {
// Code to be executed when an ad opens an overlay that
// covers the screen.
}
@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 user is about to return
// to the app after tapping on an ad.
}
});
}
}
activity_main.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
app:adSize="SMART_BANNER"
app:adUnitId="ca-app-pub-3940256099942544/6300978111"></com.google.android.gms.ads.AdView>
</LinearLayout>
'프로그래밍' 카테고리의 다른 글
안드로이드 - 쉽고 간단하게 타이틀바 없애기 (0) | 2020.12.30 |
---|---|
안드로이드 - 전면광고 + 배너광고 (0) | 2020.12.29 |
스프링 최신버전 확인 Index of release/org/springframework/spring (0) | 2020.12.27 |
방문자 카운터 쉽게 코딩하기 (0) | 2020.12.27 |
무료로 쉽게 웹 호스팅, 도메인 등록하기(netlify, freenom) -2 (0) | 2020.12.27 |
댓글