欢迎使用有米广告平台的android端SDK,以下将为您介绍如何在android程序中嵌入有米广告。
步骤一:将youmiad-android.jar导入您的工程中。
Ø右键您的工程根目录,选择“Properties”
Ø在左面板中选择“Java Build Path”
Ø然后选择“Libraries”标签
Ø点击“Add External JARs…”
Ø选择youmiad-android.jar的目录路径
Ø点击“OK”即导入成功
步骤二:在工程中的AndroidManifest.xml中添加以下代码,并写入您的App ID和App Secret。
<!-- 该应用程序的 App ID and App Seceret
-->
<meta-data android:value="abcdef1234567890" android:name="UmAd_APP_SEC" />
<meta-data android:value="1234567890abcdef"
android:name="UmAd_APP_ID" />
</application>
<!-- 有米广告 SDK permissions -->
<uses-permission android:name="android.permission.INTERNET" />
注意:UmAd_APP_ID就是你应用程序的发布ID,在value那里填上你的发布ID就行了,如此处为"1234567890abcdef"。千万不可改变"UmAd_APP_ID" ,程序需要这个Key来查找对应的Value。"UmAd_APP_SEC"同理。UmAd_APP_ID和 UmAd_APP_SEC这两个ID是在 平台网站上提交应用时产生的发布ID和应用密码,而且每个应用的这两个ID都是唯一的。
步骤三:在res/values文件夹中添加attrs.xml。如果你没有添加这个文件,那你将不能在layout中设置AdView的属性。
attrs.xml文件的内容如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleablename="net.youmi.android.AdView">
<attr name="testing" format="boolean" />
<attr name="backgroundColor" format="color" />
<attr name="textColor" format="color" />
<attr name="keywords" format="string" />
<attr name="refreshInterval" format="integer" />
<attr name="isGoneWithoutAd" format="boolean" />
<attr name="changeAdAnimation" format="boolean"/>
</declare-styleable>
</resources>
说明:
ØTesting:测试模式,如果是在调试程序中,建议设置为“true”,但是在发布程序前,一定要设置为false。默认为false。
ØbackgroundColor:设置广告视图的背景颜色
ØtextColor:设置广告文字的颜色
ØrefreshInterval:设置广告刷新率。默认为30s,设置范围为30s-200s
ØchangeAdAnimation:换广告的效果,true为翻转,false为淡入淡出
步骤四:在main.xml中布局有米广告视图。
以下为一个实例:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:umadsdk="http://schemas.android.com/apk/res/net.youmi.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:refreshInterval="30"
- umadsdk:changeAdAnimation="true"
-
- />
- </LinearLayout>
注意:
xmlns:umadsdk="http://schemas.android.com/apk/res/net.youmi.HelloYouMi"
这句一定要加上,不然会提示错误。其中net.youmi.HelloYouMi是你应用程序包名
以下图示为成功添加有米广告的效果图: