Android应用运行正常但Admob无法显示

时间:2015-05-20 02:28:35

标签: android admob

我有问题,我整合了它不显示AdMob天鹅绒。每个人都可以帮助我吗? 这是我添加de show ads的代码。 在activity_play.xml中添加admob

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"

    >
   <RelativeLayout
        android:id="@+id/rlstatus"
        android:layout_width="fill_parent"
        android:layout_height="0px"
        android:layout_weight="0.3" >
        <TextView
            android:id="@+id/scoreCount"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_marginLeft="15dp"
            android:textSize="16sp"
            android:textStyle="bold"
            android:textColor="#fffd7a"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:layout_alignParentLeft="true"/>

        <TextView
            android:id="@+id/hitCount"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:textSize="16sp"
            android:textStyle="bold"
            android:textColor="#fffd7a"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="15dp"
            android:layout_toRightOf="@id/scoreCount"/>

        <ImageView
            android:id="@+id/imgSound"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_alignParentRight="true"
            android:layout_marginRight="15dp"
            android:src="@drawable/sound" />
        <ImageView
            android:id="@+id/imgHint"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_marginRight="15dp"
            android:layout_toLeftOf="@id/imgSound"
            android:src="@drawable/hint" />
        <TextView
            android:id="@+id/hintCount"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_marginRight="26dp"
            android:textSize="16sp"
            android:textStyle="bold"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:layout_toLeftOf="@id/imgSound"/>
    </RelativeLayout>
// them vao admob
  <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-4506687331864737/xxxxxxxxx">
    </com.google.android.gms.ads.AdView>

</LinearLayout>

PlayAtivity.java中的此代码

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

        //them vao admob
        // Prepare the Interstitial Ad
        interstitial = new InterstitialAd(PlayActivity.this);
        // Insert the Ad Unit ID
        interstitial.setAdUnitId("ca-app-pub-4506687331864737/xxxxxxxx");


        //Locate the Banner Ad in activity_main.xml
        AdView adView = (AdView) this.findViewById(R.id.adView);

        // Request for Ads
        AdRequest adRequest = new AdRequest.Builder()
        //.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
        //.addTestDevice("95F9D0E7976AC34B40EC660FF460782D") //Random Text
                .build();

        // Load ads into Banner Ads
        adView.loadAd(adRequest);

        // Load ads into Interstitial Ads
        interstitial.loadAd(adRequest);


        LoadConfigParams();
        LoadSharedPreferences();
        LoadResources();
        LoadListeners();        
        LoadStage(mCurStage);
    //  LoadAds();
    // Prepare an Interstitial Ad Listener
        interstitial.setAdListener(new AdListener() {
                    public void onAdLoaded() {
                        // Call displayInterstitial() function
                        displayInterstitial();

                    }
                });

    }
    // goi admob

    public void displayInterstitial() 
    {
        // If Ads are loaded, show Interstitial else show nothing.
        if (interstitial.isLoaded()) {
            interstitial.show();
        }
    }

这是Manifest中的代码

<uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="21" />

    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
// them vao quang cao
            <meta-data android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

         <!--Include the AdActivity configChanges and theme. -->
        <activity android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

    </application>

它运行正常但不显示admob。 有人能告诉我这个问题吗?

1 个答案:

答案 0 :(得分:0)

您不能表明您的意思是横幅广告还是插页式广告。

你应该看看你的logcat。它会告诉您Admob正在做什么以及为什么它没有显示任何广告。

并且从不interstitial.show()致电onAdLoaded(),除非您希望禁止您的帐户。