Где могла быть ошибка с моей установкой Admob? - PullRequest
0 голосов
/ 07 мая 2020

Белый фон ничего не показывает; тестовые значения баннера и id приложения. Я создал отдельный класс, который загружает баннер, и назвал его Ads. java.

Вот его код:

package com.androids.apps.apps.activities;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
import com.androids.apps.apps.R;

public class Ads extends AppCompatActivity {
    private AdView mAdView;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_home);
        MobileAds.initialize(this, new OnInitializationCompleteListener() {
            @Override
            public void onInitializationComplete(InitializationStatus initializationStatus) {
            }
        });
        mAdView = findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);
    }


}

Вот мой fragment_home. xml Баннер должен загрузиться здесь:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
 xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/home_root"
    android:orientation="vertical">

<LinearLayout 
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"
    android:layout_width="wrap_content"
    android:orientation="vertical"
    android:layout_height="wrap_content"
    tools:context="com.androids.apps.apps.activities.Ads">

    <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_marginTop="10dp"
        android:layout_gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="@string/ad_unit_id_banner1"/>
          </LinearLayout>


    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tv_cat_title"
        android:text="@string/collections"
        android:textStyle="bold"
        android:textSize="@dimen/text_16sp"
        android:layout_margin="@dimen/margin_5dp" />





    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/category_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

Вот мой AndroidManifest. xml

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

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

    <application

        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"

        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".activities.GeneralActivity"
            android:theme="@style/AppTheme.NoActionBar"
            android:screenOrientation="portrait"/>
        <activity
            android:name=".activities.DetailActivity"
            android:theme="@style/AppTheme.NoActionBar"
            android:screenOrientation="portrait"/>
        <activity
            android:name=".activities.MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar"
            android:screenOrientation="portrait"/>
        <activity
            android:name=".activities.SplashActivity"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".activities.SecondActivity"
            android:theme="@style/AppTheme.NoActionBar"
            android:screenOrientation="portrait"/>

        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${packageName}"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/fileprovider" />
        </provider>

            <meta-data
                android:name="com.google.android.gms.ads.APPLICATION_ID"
                android:value="@string/app_id"/>
        <meta-data
            android:name="com.google.android.gms.ads.AD_MANAGER_APP"
            android:value="true" />

    </application>

</manifest>

Вот мой: gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.androids.apps.apps"
        minSdkVersion 16
        targetSdkVersion 29
        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 'com.google.android.material:material:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'



    //custom dependencies




    implementation 'com.makeramen:roundedimageview:2.3.0'
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
    implementation 'com.felipecsl.asymmetricgridview:library:2.0.1'
    implementation 'com.squareup.okhttp3:okhttp:3.10.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'com.android.volley:dc-volley:1.1.0'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.github.mancj:MaterialSearchBar:0.8.2'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.github.medyo:android-about-page:1.2.5'
    implementation 'com.github.chrisbanes:PhotoView:2.3.0'
    implementation 'com.android.support:support-compat:28.0.0'
    implementation 'com.google.android.gms:play-services-ads:18.3.0'


}

проект gradle

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

buildscript {
    repositories {
        google()
        jcenter()
        mavenCentral()
        google()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3'
        classpath 'com.google.gms:google-services:4.3.3'



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

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url "https://jitpack.io" }
        google()

    }
}

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

мучаюсь 5 дней но ни разу не показывает

...