How do I make a banner ads appear in this case?

Asked

Viewed 21 times

-1

What’s missing or wrong for the banners to appear? I followed all the documentation, but it has different information, one at a time.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".resultados">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="ca-app-pub-9311879766745441~9248555439"/>


</application>

Mainactivity

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    AdView adView = new AdView(this);
    adView.setAdSize(AdSize.BANNER);
    adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
    mAdView = findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);

XML

     android:layout_width="match_parent"
     android:layout_height="match_parent">

  <com.google.android.gms.ads.AdView
   android:id="@+id/adView"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_below="@+id/bbb3"
   android:layout_alignParentBottom="true"
android:layout_marginTop="157dp"
android:layout_marginBottom="260dp"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id" />
 build.gradle app

 apply plugin: 'com.android.application'
 apply plugin: 'com.google.gms.google-services'


          android {
compileSdkVersion 28
buildToolsVersion "29.0.2"
defaultConfig {
    applicationId "com.tyuu"
    minSdkVersion 21
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}

}

 dependencies {
 implementation fileTree(dir: 'libs', include: ['*.jar'])
 implementation 'androidx.appcompat:appcompat:1.1.0'
 implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
 implementation 'com.google.firebase:firebase-auth:16.0.5'
 implementation 'com.google.firebase:firebase-core:16.0.4'
 implementation 'com.google.firebase:firebase-database:16.0.4'
 implementation 'com.google.firebase:firebase-storage:16.0.4'

implementation 'com.google.firebase:firebase-ads:17.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

implementation 'com.squareup.picasso:picasso:2.5.2'

}

1 answer

0

I don’t see anything wrong with your code, just a few unnecessary lines but nothing that can cause errors.

Note that the ads only appear in the RELEASE version of the app, in the DEBUG version the ads are not loaded by default!

Try to make a RELEASE version and see if something will appear!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.