简体   繁体   English

为什么admob在测试时没有出现? 我的代码出了什么问题?

[英]why admob doesn't appear while testing ? What's wrong with my code?

Help me guy's i know there are lot's of question like that but no one is worked for me . 帮助我的家伙,我知道有很多问题,但没有人为我工作。 I have three tabs with three fragment each fragment contain a listview I want to put AdMob at the bottom of each list view but add doesn't appear at the emulator. 我有三个选项卡,其中三个片段,每个片段包含一个列表视图,我想将AdMob放在每个列表视图的底部,但添加不会出现在模拟器中。

Here is my code . 这是我的代码。

activity_main.xml activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
    tools:context="androidthirst.company.abhi.totalenglish.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.AppBarOverlay" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tab_layout"
            style="@style/MyCustomTabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabGravity="fill"
            app:tabMode="fixed" />
    </android.support.design.widget.AppBarLayout>

        <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
        <include layout="@layout/content_tab_layout_demo" />

    <RelativeLayout
        android:layout_width="match_parent"

        android:layout_height="wrap_content">
        <com.google.android.gms.ads.AdView
            android:id="@+id/adView1"

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_alignParentBottom="true"
            ads:adSize="BANNER"
            ads:adUnitId="@string/band">
        </com.google.android.gms.ads.AdView>
    </RelativeLayout>

</android.support.design.widget.CoordinatorLayout>

Here is the code of ActivityMain.java 这是ActivityMain.java的代码

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        RateItDialogFragment.show(this,getFragmentManager());

        setContentView(R.layout.activity_main);
        MobileAds.initialize(getApplicationContext(), "ca-app-pub-8835951437809468~5344380934");

        AdView mAdView = (AdView) findViewById(R.id.adView1);
        AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).addTestDevice("3FB54EBF85D756B8").build();
        mAdView.loadAd(adRequest);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.getMenu();
        setSupportActionBar(toolbar);
        TabLayout tabLayout =(TabLayout)findViewById(R.id.tab_layout);
        tabLayout.addTab(tabLayout.newTab().setText("GRAMMAR"));
        tabLayout.addTab(tabLayout.newTab().setText("TENSE"));
        tabLayout.addTab(tabLayout.newTab().setText("SPOKEN ENGLISH"));

please help me to shortout this issue 请帮我简短一下这个问题

And that's the image of my application Click here to see image 这就是我的应用程序的图像点击这里查看图像

Admob needs Google Play Services installed on device. Admob需要在设备上安装Google Play服务。 make sure google play services installed on emulator. 确保在模拟器上安装Google Play服务。

instead of .addTestDevice(AdRequest.DEVICE_ID_EMULAT‌​OR) 而不是.addTestDevice(AdRequest.DEVICE_ID_EMULAT‌​OR)

add .addTestDevice("YOUR_HASHED_DEVICE_ID") 添加.addTestDevice("YOUR_HASHED_DEVICE_ID")

as described in this post . 如在此描述的职位

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM