android应用中加广告(通过有米平台)
2012-03-02 10:58
267 查看
这个我来帮你,我前几天刚做了个: 不过我用的是有米,不会出现你这个问题: 1:注册用户,下载jar包: 去 http://www.youmi.net/ 注册个账户,然后 添加一个应用 2:在manifest.xml文件中配置: <uses-permission android:name="android.permission.INTERNET" /> 3:在你的activity种加入: //请务必使用静态的方法初始化AdManager,设置AppId、密码、广告请求间隔和 //测试模式等参数。 static{ //第一个参数是AppId //第二个参数是应用密码 //第三个参数是请求广告的间隔,有效的设置值为30 至200,单位为秒 //第四个参数是设置测试模式,设置为true 时,广告的展示和点击记录无 // 效,以测试模式运行。设置为false 时,广告的展示和点 // 击记录有效,以发布模式运行。请设置为false。 AdManager.init("df587cb8a2c2a013 ","ef967beb5489644e ", 30, false); AppId 和 应用密码是你在 http://www.youmi.net添加应用后得到的 4:在res/values 文件夹中添加attrs.xml。 attrs.xml 文件的内容如下: <?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="net.youmi.android.AdView"> <attr name="backgroundColor" format="color" /> <!--广告条的纯色背景色--> <attr name="startbackgroundColor" format="color" /> <!--广告条的渐变背景色起始颜色--> <attr name="endbackgroundColor" format="color" /> <!--广告条的渐变背景色的结束颜色--> <attr name="clickBackgroundColor" format="color" /> <!--广告条被点击时的背景色--> <attr name="textColor" format="color" /> <!--字体颜色--> <attr name="backgroundTransparent" format="integer"/> <!--背景透明度--> </declare-styleable> </resources> 5:在main.xml 中布局有米广告视图。 以下为一个实例: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/andro id" xmlns:umadsdk="http://schemas.android.com/apk/res/net.y oum i.HelloYouMi" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content " android:textSize="20px" android:text="@string/hello" /> <net.youmi.android.AdView android:id="@+id/ad" android:layout_width="fill_parent" android:layout_height="wrap_content" umadsdk:textColor="#0fff22" umadsdk:backgroundTransparent="155" umadsdk:startbackgroundColor="#2B2B2B" umadsdk:endbackgroundColor="#63B8FF" umadsdk:clickBackgroundColor="#1E90FF" /> </LinearLayout> 注意: xmlns:umadsdk="http://schemas.android.com/apk/res/net.youmi.H ell oYouMi" 这句一定要加上,不然会提示错误。其中net.youmi.HelloYouMi是你应用程序包 名 6:请务必在有广告控件的Activity里面重载onDestroy() 方法,并调用adView.OnDestroy(). @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); try { AdView adView= (AdView) findViewById(R.id.ad); if(adView!=null) { adView.OnDestroy(); } } catch (Exception e) { // TODO: handle exception } } 下面是我写的一个例子源码,你可以去下载下来看下: |
相关文章推荐
- Android应用盈利广告平台的嵌入方法详解
- Android学习系列(34)--App应用之发布各广告平台版本
- Android应用盈利广告平台的嵌入方法详解
- Android应用盈利广告平台的嵌入方法详解
- Android应用盈利广告平台的嵌入方法详解
- Android接入多盟广告SDK--让你的APP通过广告平台赚钱
- Android学习系列(34)--App应用之发布各广告平台版本
- Android应用盈利广告平台的嵌入方法详解
- Android应用盈利广告平台的嵌入方法详解
- Android应用盈利广告平台的嵌入方法详解
- Android学习系列(34)--App应用之发布各广告平台版本
- Android开发总结:个人开发者如何通过广告平台赚钱
- Android应用盈利广告平台的嵌入方法详解
- 关于第三方应用(Android平台)通过微信分享文字、图片的问题研究。
- Android应用盈利广告平台的嵌入方法详解
- Android应用盈利广告平台的嵌入方法详解
- Android笔记之:App应用之发布各广告平台版本的详解
- Android平台向web应用get、post方式提交信息案例
- Android平台向web应用get、post方式提交信息案例
- 如何通过cocos creator发布原生android应用