build.gradle

dependencies {

    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile 'com.android.support:appcompat-v7:21.0.3'

    compile 'com.google.android.gms:play-services:6.5.87'

}

MainActivity.java

  adView = new AdView(this);//new AdView(this);

        adView.setAdUnitId("ca-app-pub-???????????????/5335932412");

        adView.setAdSize(AdSize.SMART_BANNER);


        layout = (RelativeLayout) findViewById(R.id.mainLayout);

        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(

                RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

        layout.addView(adView, params);

        //39DDB5F0BC9A833F635156A14F3C

        adRequest = new AdRequest.Builder()

        .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)

        .addTestDevice("39DDB255B5F0BC9A833F635156A14F3C").build();

        adView.loadAd(adRequest);


        adView.setAdListener(new AdListener() {

            @Override

            public void onAdLoaded() {

                super.onAdLoaded();

                Log.e("adView", "onLoad");

                layout.setVisibility(View.VISIBLE);

            }

        });


AndroidManifest.xml

 <activity android:name="com.google.android.gms.ads.AdActivity"

            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"

            android:theme="@android:style/Theme.Translucent" />

        <meta-data android:name="com.google.android.gms.version"

            android:value="@integer/google_play_services_version"/>

</application>

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

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

Posted by 에브리피플
,