【问题标题】:why admob doesn't appear while testing ? What's wrong with my code?为什么测试时没有出现admob?我的代码有什么问题?
【发布时间】:2016-09-15 04:55:34
【问题描述】:

帮帮我,我知道有很多这样的问题,但没有人适合我。我有三个带有三个片段的选项卡,每个片段包含一个列表视图 我想将 AdMob 放在每个列表视图的底部,但 add 没有出现在模拟器中。

这是我的代码。

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>

下面是代码 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"));

请帮我解决这个问题

这就是我的应用程序的图像 Click here to see image

【问题讨论】:

    标签: java android listview android-fragments admob


    【解决方案1】:

    Admob 需要在设备上安装 Google Play 服务。 确保在模拟器上安装了 google play 服务。

    【讨论】:

    • 谢谢先生,我该如何检查?我正在使用 Genymotion
    • 您正在使用genymotion,并且在genymotion中默认没有安装google play服务。你需要安装(闪存)。
    • 如果我想在真机上查看?代码有没有问题?
    • AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build(); 这可能会产生问题。但你可以试试。
    • 不起作用我认为我的代码有问题,请您解决一下。
    【解决方案2】:

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

    添加.addTestDevice("YOUR_HASHED_DEVICE_ID")

    post 中所述。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-05
      • 2015-04-01
      • 2021-09-11
      • 2011-07-28
      相关资源
      最近更新 更多