Admob广告没有显示,我已经正确设置了所有代码,但仍然没有显示

时间:2019-02-24 14:43:51

标签: java android firebase admob

This is App ID I have added it in Android Manifest file

<?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.rishavgmail.coder.carescountrysactionresourcesexigencyservices">

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

    <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/AppTheme"
        tools:ignore="GoogleAppIndexingWarning">
        <activity android:name=".UserLoginActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".HomeActivity" />
        <activity android:name=".UserLoginPage" />
        <activity android:name=".UserRegistration" />
        <activity android:name=".AuthorizationLoginPage" />
        <activity android:name=".OtpStepOne" />
        <activity android:name=".VerifyPhone" />
        <activity android:name=".AuthorityRegistration" />
        <activity android:name=".AuthorityHome" />
        <activity android:name=".AuthReg" />
        <activity android:name=".AuthLoginPage" />
        <activity android:name=".SplashScreen"></activity>
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-*******381606112~********91"/>
    </application>

</manifest>

My AdMob AdUnitId in the string.xml file

<resources>
    <string name="app_name">C A R E S : Country\'s Action Resources Exigency Services</string>
    <string name="open">Open</string>
    <string name="close">Close</string>
    <string name="event_name">Event/Party/Restaurant/Other Name </string>
    <string name="event_location">Event Address</string>
    <string-array name="events">
        <item>SELECT AN EVENT</item>
        <item>PARTY</item>
        <item>RESTAURANT</item>
        <item>OTHER EVENTS</item>
    </string-array>
    <string name="foods">Foods</string>
    <string name="btn_send">Inform Authority</string>
    <string name="copyright">
        Developed by 16Bit Coders
    </string>
    <string name="userphone">
        Your Phone Number
    </string>
    <string name="user_login_button">
        LOGIN AS USER
    </string>
    <string name="authority_login_button">
        LOGIN AS AUTHORITY
    </string>
    <string name="user_email">Email</string>
    <string name="user_password">Password</string>
    <string name="confirm_password">Confirm Password</string>
    <string name="login">LOGIN</string>
    <string name="register">REGISTER</string>
    <string name="fname">First Name</string>
    <string name="lname">Last Name</string>
    <string name="welcome_authority">Authority Login</string>
    <string name="send_otp">SEND OTP</string>
    <string name="verify_otp">Verify OTP</string>
    <string name="enter_otp">Enter OTP</string>
    <string name="enter_aadhaar">Aadhar Card Number</string>
    <string-array name="gender">
        <item>SELECT GENDER</item>
        <item>MALE</item>
        <item>FEMALE</item>
    </string-array>
    <string-array name="location">
        <item>91</item>
    </string-array>
    <string name="thanks">Thank You So Much</string>
    <string name="thanks2">You Just Take a Part of Helping Needy People</string>
    <string name="hero">Awesome.. You are a real Hero !!</string>
    <string-array name="ngo_list">
        <item>Jeevan Life Seva Sangstha</item>
        <item>Astha Foundation</item>
        <item>AIWA NGO India</item>
        <item>All India Human Rights Bureau</item>
        <item>Chain Foundation</item>
        <item>Helping Hand Foundation</item>
        <item>Human Wellfair Foundation</item>

    </string-array>
    <string name="banner_ad">ca-app-pub-*******381606112/*******732</string>

</resources>

I have called adunitId in the xml file from string.xml file

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="192dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <ImageView
                android:id="@+id/imageView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scaleType="center"
                app:srcCompat="@drawable/logo"
                tools:layout_editor_absoluteX="174dp"
                tools:layout_editor_absoluteY="54dp" />
        </android.support.design.widget.AppBarLayout>

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/nestedScrollView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="8dp"
            app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"
            app:layout_constraintTop_toTopOf="parent">

            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:context=".UserLoginActivity">

                <Button
                    android:id="@+id/user_login_button"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="8dp"
                    android:layout_marginTop="300dp"
                    android:layout_marginEnd="8dp"
                    android:background="@drawable/login_button_style"
                    android:elevation="10dp"
                    android:text="@string/user_login_button"
                    android:textColor="@color/white"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <Button
                    android:id="@+id/authority_login_button"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="8dp"
                    android:layout_marginTop="20dp"
                    android:layout_marginEnd="8dp"
                    android:background="@drawable/login_button_style"
                    android:elevation="10dp"
                    android:text="@string/authority_login_button"
                    android:textColor="@color/white"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/user_login_button" />

            </android.support.constraint.ConstraintLayout>
        </android.support.v4.widget.NestedScrollView>

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginBottom="8dp"
            android:text="@string/copyright"
            app:layout_constraintBottom_toTopOf="@+id/adView2"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent" />

        <com.google.android.gms.ads.AdView
            xmlns:ads="http://schemas.android.com/apk/res-auto"
            android:id="@+id/adView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginBottom="8dp"
            app:layout_constraintBottom_toBottomOf="@+id/nestedScrollView"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            ads:adSize="BANNER"
            ads:adUnitId="@string/banner_ad"/>
    </android.support.constraint.ConstraintLayout>
</android.support.design.widget.CoordinatorLayout>

And finally I setup java code to show ads in app

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.firebase.auth.FirebaseAuth;

public class UserLoginActivity extends AppCompatActivity {
    private Button btnLogin,btnAuthLogin;
    private FirebaseAuth mAuth;
    private AdView adview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_login);
        adview = findViewById(R.id.adView2);
        AdRequest adRequest = new AdRequest.Builder().build();
        adview.loadAd(adRequest);
        btnLogin = findViewById(R.id.user_login_button);
        btnAuthLogin = findViewById(R.id.authority_login_button);
        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(UserLoginActivity.this,UserLoginPage.class));
            }
        });
        btnAuthLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =new Intent(UserLoginActivity.this,AuthLoginPage.class);
                startActivity(intent);
            }
        });
    }

}

我现在可以做什么,我已经在Google上进行了研究,也查看了StackOverflow的帖子,但是找不到任何解决方案,我该如何解决。 即使按照Google AdMob政策,我仅在一个活动中添加了一个广告,但仍然没有展示广告 谢谢

2 个答案:

答案 0 :(得分:0)

AdMob最多需要72个小时才能批准您的帐户并开始展示广告。在此之前,您都可以使用测试广告。

Test ad IDs

答案 1 :(得分:0)

您已编写了所有代码,但没有在何处初始化Admob SDK。应用程序启动后,使用

对其进行初始化
MobileAds.initialize(getApplicationContext(), getString(R.string.YOUR_APP_ID));