前提・実現したいこと
メインアクティビティにてバナー広告の実装
発生している問題・エラーメッセージ
アプリを起動してもテストバナーが表示されません。
エラーメッセージなし
該当のソースコード
Manifest
1<meta-data 2 android:name="com.google.android.gms.ads.APPLICATION_ID" 3 android:value="@string/ads_AppId"/>
mainactivity.java
1 private AdView mAdView; 2 @Override 3 protected void onCreate(Bundle savedInstanceState) { 4 super.onCreate(savedInstanceState); 5 setContentView(R.layout.activity_main); 6 MobileAds.initialize(this, new OnInitializationCompleteListener() { 7 @Override 8 public void onInitializationComplete(InitializationStatus initializationStatus) { 9 } 10 }); 11 mAdView = findViewById(R.id.adView); 12 AdRequest adRequest = new AdRequest.Builder().build(); 13 mAdView.loadAd(adRequest); 14省略 15} 16
xml
1<?xml version="1.0" encoding="utf-8"?> 2<RelativeLayout 3 xmlns:android="http://schemas.android.com/apk/res/android" 4 xmlns:app="http://schemas.android.com/apk/res-auto" 5 xmlns:tools="http://schemas.android.com/tools" 6 xmlns:ads="http://schemas.android.com/apk/res-auto" 7 android:layout_width="match_parent" 8 android:layout_height="match_parent" 9 tools:context=".MainActivity"> 10 <LinearLayout 11 android:id="@+id/linearLayout" 12 android:layout_width="match_parent" 13 android:layout_height="wrap_content" 14 android:orientation="vertical"> 15 <TextClock /> 16 <Button/> 17 <LinearLayout 18 android:layout_width="match_parent" 19 android:layout_height="wrap_content" 20 android:orientation="vertical"> 21 <LinearLayout 22 android:layout_width="match_parent" 23 android:layout_height="wrap_content" 24 android:orientation="horizontal"> 25 <ImageButton/> 26 <ImageButton/> 27 </LinearLayout> 28 <LinearLayout 29 android:layout_width="match_parent" 30 android:layout_height="match_parent" 31 android:orientation="horizontal"> 32 <ImageButton/> 33 <ImageButton/> 34 </LinearLayout> 35 </LinearLayout> 36表示したいバナー広告 37 <com.google.android.gms.ads.AdView 38 android:id="@+id/adView" 39 android:layout_width="wrap_content" 40 android:layout_height="wrap_content" 41 ads:adSize="BANNER" 42 ads:adUnitId="@string/ads_UnitId_Banner" /> 43 </LinearLayout> 44</RelativeLayout>
ProjectGradle
1buildscript { 2 repositories { 3 google() 4 mavenCentral() 5 } 6 dependencies { 7 classpath 'com.android.tools.build:gradle:7.1.0' 8 } 9} 10 11allprojects { 12 repositories{ 13 google() 14 mavenCentral() 15 } 16}
ModuleGradle
1dependencies { 2 implementation 'com.google.android.gms:play-services-ads:20.5.0' 3}
試したこと
公式ページを参考に行いました。
Adviewの読み込み等のエラーは出ておらず、
なぜ表示されないのかわからず、質問させていただきました。
お手数ですが、ご教示いただければ幸いです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。