Android Admob横幅广告未在应用程序中显示

Android Admob横幅广告未在应用程序中显示,android,android-fragments,Android,Android Fragments,我的应用程序在没有显示任何广告,请帮助,下面是代码。我搜索了很多,但我所能看到的是我的代码中没有错误,或者可能是我不知道错误在哪里 主要活动 <android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/pager"

我的应用程序在没有显示任何广告,请帮助,下面是代码。我搜索了很多,但我所能看到的是我的代码中没有错误,或者可能是我不知道错误在哪里

主要活动

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity" >

    <RelativeLayout xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <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"
            android:layout_alignParentBottom="true"
            ads:adSize="SMART_BANNER"
            ads:adUnitId="ca-app-pub-33xxxxxxxxxxxxxxxxxxxxx"/>
        <ListView
            android:id="@+id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:divider="@null"
            android:dividerHeight="0dp">
        </ListView>    
    </RelativeLayout>
</android.support.v4.view.ViewPager>

main活动

package com.nyt.ilm.ilmsarf;

import java.util.ArrayList;
import java.util.List;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.nyt.ilm.ilmsarf.P1.OnFragmentInteractionListener;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.LayoutParams;
import android.view.ViewTreeObserver;
import android.widget.ListView;
import android.widget.RelativeLayout;

public class MainActivity extends FragmentActivity implements
            OnFragmentInteractionListener {

    ViewPager viewpager;
    Context mContext = MainActivity.this;
    SharedPreferences appPreferences;
    boolean isAppInstalled = false;
    /* Your ad unit id. Replace with your actual ad unit id. */
    public boolean adViewHeightSet = false;

    @Override
    protected void onCreate(Bundle arg0) {
        // TODO Auto-generated method stub
        super.onCreate(arg0);

        appPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        isAppInstalled = appPreferences.getBoolean("isAppInstalled", false);
        if (isAppInstalled == false) {
            // add shortcutIcon code here
        Intent shortcutIntent = new Intent(getApplicationContext(),
            MainActivity.class);

        shortcutIntent.setAction(Intent.ACTION_MAIN);
        // shortcutIntent is added with addIntent
        Intent addIntent = new Intent();
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
                addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "IlmSarf");
                addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                        Intent.ShortcutIconResource.fromContext(
                                getApplicationContext(), R.drawable.ic_launcher));

        addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
                // finally broadcast the new Intent
                getApplicationContext().sendBroadcast(addIntent);
                // finally isAppInstalled should be true.
                SharedPreferences.Editor editor = appPreferences.edit();
                editor.putBoolean("isAppInstalled", true);
                editor.commit();
        }

        setContentView(R.layout.activity_main);
        viewpager = (ViewPager) findViewById(R.id.pager);
        FragmentPagerAdapter fm = new MyPageAdapter(getSupportFragmentManager());
        viewpager.setAdapter(fm);
        viewpager.setCurrentItem(fm.getCount() - 1);

        // Ad Banner

        AdView adView = (AdView) this.findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        adView.loadAd(adRequest);

        adView.getViewTreeObserver().addOnGlobalLayoutListener(
                    new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            if (adViewHeightSet) { return; }

            AdView adView = (AdView) findViewById(R.id.adView);
            ListView list = (ListView) findViewById(R.id.list);
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
            params.setMargins(0, 0, 0, adView.getHeight() + 15);
            list.setLayoutParams(params);
            adViewHeightSet = true;
        }
        });

    }

    @Override
    public void onFragmentInteraction(Uri uri) {
        // TODO Auto-generated method stub

    }

}
class MyPageAdapter extends FragmentPagerAdapter {
    private List<Fragment> fragments;

    public MyPageAdapter(FragmentManager fm) {
        super(fm);
        // TODO Auto-generated constructor stub
        this.fragments = new ArrayList<Fragment>();
        fragments.add(new P1());
        fragments.add(new P2());
        fragments.add(new P3());
        fragments.add(new P4());
        fragments.add(new P5());
        fragments.add(new P6());
        fragments.add(new P7());
        fragments.add(new P8());
        fragments.add(new P9());
        fragments.add(new P10());
        fragments.add(new P11());
        fragments.add(new P12());
        fragments.add(new P13());
        fragments.add(new P14());
        fragments.add(new P15());
        fragments.add(new P16());
        fragments.add(new P17());
        fragments.add(new P18());
        fragments.add(new P19());
        fragments.add(new P20());
        fragments.add(new P21());
        fragments.add(new P22());
        fragments.add(new P23());
        fragments.add(new P24());
        fragments.add(new P25());
        fragments.add(new P26());
        fragments.add(new P27());
        fragments.add(new P28());
        fragments.add(new P29());
        fragments.add(new P30());
        fragments.add(new P31());
        fragments.add(new P32());
        fragments.add(new P33());
        fragments.add(new P34());
        fragments.add(new P35());
        fragments.add(new P36());
        fragments.add(new P37());
        fragments.add(new P38());
        fragments.add(new P39());
        fragments.add(new P40());
        fragments.add(new P41());
        fragments.add(new P42());
        fragments.add(new P43());
        fragments.add(new P44());
        fragments.add(new P45());
        fragments.add(new P46());
        fragments.add(new P47());
        fragments.add(new P48());
        fragments.add(new P49());
        fragments.add(new P50());
        fragments.add(new P51());
        fragments.add(new P52());
        fragments.add(new P53());
        fragments.add(new P54());
        fragments.add(new P55());
        fragments.add(new P56());
        fragments.add(new P57());

    }

    @Override
    public Fragment getItem(int position) {
        // TODO Auto-generated method stub
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return fragments.size();
    }

}
package com.nyt.ilm.ilmsarf;
导入java.util.ArrayList;
导入java.util.List;
导入com.google.android.gms.ads.AdRequest;
导入com.google.android.gms.ads.AdView;
导入com.nyt.ilm.ilmsarf.P1.OnFragmentInteractionListener;
导入android.content.Context;
导入android.content.Intent;
导入android.content.SharedReferences;
导入android.net.Uri;
导入android.os.Bundle;
导入android.preference.PreferenceManager;
导入android.support.v4.app.Fragment;
导入android.support.v4.app.FragmentActivity;
导入android.support.v4.app.FragmentManager;
导入android.support.v4.app.FragmentPagerAdapter;
导入android.support.v4.view.ViewPager;
导入android.support.v4.view.ViewPager.LayoutParams;
导入android.view.ViewTreeObserver;
导入android.widget.ListView;
导入android.widget.RelativeLayout;
公共类MainActivity扩展了FragmentActivity实现
OnFragmentInteractionListener{
查看页面查看页面;
Context mContext=MainActivity.this;
共享数据引用appPreferences;
布尔值=假;
/*您的广告单元id。替换为您的实际广告单元id*/
公共布尔值adViewHeightSet=false;
@凌驾
创建时受保护的void(包arg0){
//TODO自动生成的方法存根
super.onCreate(arg0);
appPreferences=PreferenceManager.getDefaultSharedPreferences(此选项);
isAppInstalled=appPreferences.getBoolean(“isAppInstalled”,false);
如果(isAppInstalled==false){
//在此处添加快捷键代码
Intent SHORTCUTITENT=新的Intent(getApplicationContext(),
主要活动(课堂);
shortcutient.setAction(Intent.ACTION_MAIN);
//shortcutient添加了addint
Intent addIntent=新Intent();
addIntent.putExtra(Intent.EXTRA\u SHORTCUT\u Intent,shortcuttent);
addIntent.putExtra(Intent.EXTRA_快捷方式_名称,“IlmSarf”);
addIntent.putExtra(Intent.EXTRA\u快捷方式\u图标\u资源,
Intent.shortcutionResource.fromContext(
getApplicationContext(),R.drawable.ic_启动器);
addIntent.setAction(“com.android.launcher.action.INSTALL_快捷方式”);
//最后广播新的意图
getApplicationContext().sendBroadcast(附加内容);
//最后,这应该是真的。
SharedReferences.Editor=appPreferences.edit();
编辑器.putBoolean(“IsapingStalled”,true);
commit();
}
setContentView(R.layout.activity_main);
viewpager=(viewpager)findViewById(R.id.pager);
FragmentPagerAdapter fm=新的MyPageAdapter(getSupportFragmentManager());
设置适配器(fm);
viewpager.setCurrentItem(fm.getCount()-1);
//广告横幅
AdView AdView=(AdView)this.findviewbyd(R.id.AdView);
AdRequest AdRequest=新建AdRequest.Builder().build();
adView.loadAd(adRequest);
adView.getViewTreeObserver().addOnGlobalLayoutListener(
新建ViewTreeObserver.OnGlobalLayoutListener(){
@凌驾
公共图书馆{
if(adViewHeightSet){return;}
AdView AdView=(AdView)findViewById(R.id.AdView);
ListView列表=(ListView)findViewById(R.id.list);
RelativeLayout.LayoutParams params=新的RelativeLayout.LayoutParams(LayoutParams.MATCH\u父级,LayoutParams.MATCH\u父级);
参数setMargins(0,0,0,adView.getHeight()+15);
list.setLayoutParams(参数);
adViewHeightSet=true;
}
});
}
@凌驾
公共void onFragmentInteraction(Uri){
//TODO自动生成的方法存根
}
}
类MyPageAdapter扩展了FragmentPagerAdapter{
私有列表片段;
公共MyPageAdapter(FragmentManager fm){
超级(fm);
//TODO自动生成的构造函数存根
this.fragments=new ArrayList();
添加(新的P1());
添加(新的P2());
添加(新的P3());
添加(新的P4());
添加(新的P5());
添加(新的P6());
添加(新的P7());
添加(新的P8());
添加(新的P9());
添加(新的P10());
添加(新的P11());
添加(新的P12());
添加(新的P13());
添加(新的P14());
添加(新的P15());
添加(新的P16());
添加(新的P17());
添加(新的P18());
添加(新的P19());
添加(新的P20());
添加(新的P21());
添加(新的P22());
添加(新的P23());
添加(新的P24());
添加(新的P25());
添加(新的P26());
添加(新的P27());
添加(新的P28());
添加(新的P29());
添加(新的P30());
添加(新的P31());
添加(新的P32());
添加(新的P33());
添加(新的P34());
添加(新的P35());
添加(新的P36());
添加(新的P37());
添加(新的P38());
添加(新的P39());
添加(新的P40());
添加(新的P41());
添加(新的P42());
添加(新的P43());
添加(新的P44());
添加(新的P45());
添加(新的P46());
添加(新的P47());
弗拉格梅
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.nyt.ilm.ilmsarf"
    android:versionCode="3"
    android:versionName="1.3" xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />
    <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
    <uses-permission android:name='com.android.launcher.permission.UNINSTALL_SHORTCUT'/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <meta-data android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version"/>
        <activity android:label="@string/app_name" android:name="adview" />
        <activity
            android:name="com.nyt.ilm.ilmsarf.MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
    </application>
</manifest>
// Get the adView.
AdView adView = (AdView) this.findViewById(R.id.adView);

// Create an ad request. Check logcat output for the hashed device ID to
// get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
    .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)  // Change this if you are using a real device to test
    .addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
    .build();

// Start loading the ad in the background.
adView.loadAd(adRequest);
/* This function gets called when the activity is played 
 * and is where we should tell the ad to play too.  
 * For example if your phone goes to sleep then wakes up it will call this function.  
 */
@Override
public void onResume() {
    super.onResume();
    if (adView != null) {
        adView.resume();
    }
}

@Override
public void onPause() {
    if (adView != null) {
        adView.pause();
    }
    super.onPause();
}
    <meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version"/>