android banner广告接入,仅涉及技术

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|smallestScreenSize
api大于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 -->
        <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" />
(3)布局文件增加:

<com.mopub.mobileads.MoPubView
        android:id="@+id/bannerview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" />
(4)java加载广告:

 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.csdn.net/detail/ldwtill/8274095

google-play-services_lib :

http://download.csdn.net/detail/ldwtill/8274079

mopub-sdk.jar:

http://download.csdn.net/detail/ldwtill/8274101

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值