Adview не отображается в Android

1

Я пытаюсь разместить рекламу в приложении, и у меня возникают проблемы, потому что приложение компилируется нормально, и я вижу добавление в предварительном просмотре студии android, но нет в приложении:

Изображение приложения в программе предварительного просмотра И изображение приложения в эмуляторе Это код макета:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorBackground_frases"
    tools:context="com.fire.app.yonunca.Frases_Activity"
    android:screenOrientation="portrait"
    >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="49dp">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_weight="30"
            android:layout_height="wrap_content"
            android:gravity="center_vertical|center_horizontal|center"
            >
            <TextView
                android:id="@+id/frases_tittle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/yonunca"
                android:textColor="#ffffff"
                android:textSize="45dp"
                android:textStyle="bold" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_weight="50"
            android:layout_height="wrap_content"
            android:gravity="center_vertical|center_horizontal|center"
            >
            <TextView
                android:id="@+id/frase_aleatoria"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/frase_aleatoria"
                android:gravity="center_horizontal"
                android:layout_gravity="center_vertical|center_horizontal|center"
                android:textColor="#ffffff"
                android:textSize="30dp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_weight="20"
            android:layout_height="wrap_content"
            android:gravity="center_vertical|center_horizontal|center"
            >
            <Button
                android:id="@+id/button_siguiente"
                android:layout_width="200dip"
                android:layout_height="40dip"
                android:theme="@style/NoAddsButton"
                android:text="SIGUIENTE"
                android:onClick="onClickNext"/>
        </LinearLayout>


        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_weight="10"
            android:layout_height="wrap_content"
            android:gravity="center_vertical|center_horizontal|center"
            >
            <com.google.android.gms.ads.AdView
                android:id="@+id/av_bottom_banner"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                ads:adSize="BANNER"
                ads:adUnitId="@string/banner_inferior_ad_unit_id" />

        </LinearLayout>

    </LinearLayout>

</android.support.constraint.ConstraintLayout>

Активность

package com.fire.app.yonunca;


import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

import java.util.Random;

public class Frases_Activity extends AppCompatActivity {

    TextView frase_aleatoria;
    CrossInfo crossinfo = new CrossInfo();
    int gamemode = crossinfo.getGameMode();

    Repositorio repositorio = new Repositorio();
    String frase_show = "me he enamorado";

    Random rand = new Random();
    int random_type = rand.nextInt(2) + 1;
    //2 is the maximum and the 1 is our minimum.

    private AdView mBottomBanner;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_frases_);

        frase_aleatoria = (TextView)findViewById(R.id.frase_aleatoria);
        getFrase();

        // Ui
        mBottomBanner = (AdView) findViewById(R.id.av_bottom_banner);

        getdeviceID_Ad();


    }

    public void getdeviceID_Ad() {
        AdRequest adRequest = new AdRequest.Builder()
                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                .build();
        mBottomBanner.loadAd(adRequest);
    }

    public void askforAd(){
        //El numero ese corresponde al id de mi movil
        AdRequest adRequest = new AdRequest.Builder()
                .addTestDevice("DEVICE_ID_EMULATOR")
                .build();
        mBottomBanner.loadAd(adRequest);
    }

манифест

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.fire.app.yonunca">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppThemeNoBar">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

builld.gradle (проект)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:4.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

build.gradle (приложение)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.fire.app.yonunca"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    compile 'com.google.firebase:firebase-ads:16.0.1'
    compile 'com.google.android.gms:play-services-auth:16.0.1'

    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'

    testImplementation 'junit:junit:4.12'

    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

apply plugin: 'com.google.gms.google-services'
Теги:
firebase
admob
ads

1 ответ

0

Я читал LogCat и обнаружил, что ошибка была:

Не удалось загрузить объявление: 3

В заключение, это означает, что код в порядке, но проблема в том, что у admob нет доступных мне объявлений прямо сейчас. Есть несколько решений, например, создание нового рекламного места в консоли admob.

Если кто-то попал сюда и у вас возникла такая же проблема, вы можете найти больше информации здесь:

не удалось загрузить объявление: 3

Admob объявление запрос всегда код возврата 3

Увидимся!

Ещё вопросы

Сообщество Overcoder
Наверх
Меню