google 广告接入,admob
官网地址:
http://developer.android.com/intl/zh-cn/google/play-services/setup.html
配置:
(1)从<sdk>/extras/android/support/拷贝google-play-services_lib 工程到自己的工程所在目录,import 进eclipse,设置为lib工程,用自己的工程对其进行引用。
(2)修改mainfest文件:
增加:
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<!-- Activity required to show ad overlays. -->
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:theme="@android:style/Theme.Translucent"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
注意:
screenSize|smallestScreenSizeapi大于13才能进行编译
(3)banner广告增加布局:
private AdView mAdView;
mAdView = new AdView(this);
mAdView.setAdUnitId(getResources().getString(R.string.ad_unit_id));
mAdView.setAdSize(AdSize.BANNER);
RelativeLayout layout = (RelativeLayout) findViewById(R.id.mainLayout);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
layout.addView(mAdView, params);
mAdView.loadAd(new AdRequest.Builder().build());
mAdView.resume();
mAdView.pause();
mAdView.destroy();
也有直接使用xml添加的方式,但是发现经常会出现xml中无法实例化AdView的问题,所以干脆代码动态生成了。
ad_unit_id是你申请的key 平台地址:https://www.google.com/admob/
(3‘)interstitial广告增加布局:
官方网址说明:https://developers.google.com/mobile-ads-sdk/docs/admob/android/interstitial
private InterstitialAd mInterstitial;mInterstitial = new InterstitialAd(this);mInterstitial.setAdUnitId(getResources().getString(R.string.ad_Interstitial_unit_id));mInterstitial.loadAd(new AdRequest.Builder().build());if (mInterstitial.isLoaded()) { mInterstitial.show(); }
其他:
由于我所做的东西的特殊性,需要使用aapt对src+dex+mainfest 进行打包,所以引用lib工程的方式就不合适了,因此我将google-play-services_lib工程中的google-play-services.jar直接放到自己工程的libs下,另外工程还引用了:@integer/google_play_services_version,所以需要将google-play-services_lib工程中的version.xml放入自己的工程。如果你使用xml方式进行布局,还需要将admob_ads_attrs.xml也放置在自己的工程目录下。经过基本测试,比直接引用google-play-services_lib工程少了近1m资源,而且banner能正常显示。
mopub网盟统一接口接入:
接入地址:https://github.com/mopub/mopub-android-sdk/wiki
(1)下载full-sdk,自己的工程引用此sdk工程。
(2)mainfest 配置增加:
<!-- mopub -->(3)布局文件增加:
<activity
android:name="com.mopub.mobileads.MoPubActivity"
android:configChanges="keyboardHidden|orientation" />
<activity
android:name="com.mopub.mobileads.MraidActivity"
android:configChanges="keyboardHidden|orientation" />
<activity
android:name="com.mopub.common.MoPubBrowser"
android:configChanges="keyboardHidden|orientation" />
<activity
android:name="com.mopub.mobileads.MraidVideoPlayerActivity"
android:configChanges="keyboardHidden|orientation" />
<com.mopub.mobileads.MoPubView(4)java加载广告:
android:id="@+id/bannerview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
private MoPubView mMopubBannerView ;
mMopubBannerView = (MoPubView) findViewById(R.id.bannerview);
mMopubBannerView.setAdUnitId(Const.MOPUB_ADUNIT_CI_SUOPING_BANNER);
mMopubBannerView.setAutorefreshEnabled(true);
mMopubBannerView.loadAd();
if(mMopubBannerView != null)
mMopubBannerView.destroy();
mopub网盟加入inmobi广告
inmobi广告官网:http://china.inmobi.com/products/sdk/
(1)获取inmobi官网sdk,加到自己的工程中
(2)mopub后台配置inmobi广告
mopub网盟加入google广告
(1)从<sdk>/extras/android/support/拷贝google-play-services_lib 工程到自己的工程所在目录,import 进eclipse,设置为lib工程,用自己的工程对其进行引用。
(2)mopub后台配置google广告
参考链接:
inmobi:
http://china.inmobi.com/products/sdk/
https://www.inmobi.com/support/art/24064712/22095493/mopub-mediation-adapter-guides/
https://www.inmobi.com/support/art/23806682/22095493/mopub-adaptor-android-sdk-integration-guide/
https://www.inmobi.com/support/art/27273917/22695307/mopub-%E4%B8%8E-inmobi-android-sdk-%E9%9B%86%E6%88%90/#
https://www.inmobi.com/support/integration/23817448/22051163/android-sdk-integration-guide/
https://www.inmobi.com/support/art/26879697/22581987/sdk-android-%E9%9B%86%E6%88%90%E6%8C%87%E5%8D%97/
https://www.inmobi.com/support/art/29132193/22875877/sdk-%E9%9C%80%E8%A6%81%E7%9A%84-android-%E6%9D%83%E9%99%90/
mopub:
http://www.mopub.com/resources/
https://github.com/mopub/mopub-android-sdk/wiki/Getting-Started
https://github.com/mopub/mopub-android-sdk/wiki/Banner-Integration
https://github.com/mopub/mopub-android-sdk/wiki
google play
http://developer.android.com/intl/zh-cn/google/play-services/setup.html
资源下载:
inmobijar:
http://download.****.net/detail/ldwtill/8274095
google-play-services_lib :
http://download.****.net/detail/ldwtill/8274079
mopub-sdk.jar:
http://download.****.net/detail/ldwtill/8274101