長話短說,我喜歡比較直接的方式,好讓咱們開始吧!android
AdMob(現被Google收購)提供了移動設備加入廣告接口,並會分給發佈者必定的經濟利潤。程序員
對於Android程序員來講,午餐錢是有了。網絡
一、註冊AdMob
訪問http://www.admob.comapp
點擊這個連接ide
若是你有Google帳戶就好辦了,直接選Sign in With your Google Account佈局
![](http://static.javashuo.com/static/loading.gif)
而後輸入Google的Password就能夠登陸了ui
填寫基本帳戶信息,這個不關鍵,不是付款信息,Account Type選Publisherthis
![](http://static.javashuo.com/static/loading.gif)
而後完善付款信息google
![](http://static.javashuo.com/static/loading.gif)
注意用英文填寫,以上爲招商銀行的例子。(我也是剛用,不保證能夠收到匯款)。spa
如下爲網友總結:
1. 本人使用的是具備美圓(子)帳戶的招商銀行金卡(借記卡)
2. 在稅務信息裏面分別選擇: 中國 - 我的 - 您的姓名 - 稅務ID不填寫
3. 在付款詳細信息裏面分別選擇(這裏面都是英文):
經過 ACH/電匯付款
收款人姓名: 填寫銀行卡上面的姓名拼音(銀行卡上面有鋼印的名字)
銀行名稱: 填寫招商銀行的名稱(其餘銀行應該相似,能夠質詢具體的銀行服務員) China Merchants Bank, H.O. Shenzhen, China
銀行地址: 填寫總部地址 China Merchants Bank Tower NO.7088, Shennan Boulevard, Shenzhen, China
收款人銀行賬號/IBAN: 填寫您的借記卡帳戶
銀行 SWIFT 代碼: 每一個銀行都有的,能夠質詢客服, 招商銀行的是 CMBCCNBS(這裏不用具體到下面的分行,直接填寫國內總行的代碼就能夠了,電匯到總行後,銀行會根據您的帳戶 自動轉帳給您的)
另外 admob電匯是在金額大於100美圓(好像是這樣吧)的時候才電匯的,不是那個最小支付額度,若是當月不想電匯 能夠在收款人前面添加HOLD 來保留當前的匯款.
ok,帳戶的配置部分就先到這裏。
二、在AdMob中加入新應用
找到Sites&Apps菜單,選擇裏面的Add Site/App
![](http://static.javashuo.com/static/loading.gif)
打開後選擇Android App,輸入應用的一些基本信息
![](http://static.javashuo.com/static/loading.gif)
三、下載AdMob Android SDK
成功建立後會看到
![](http://static.javashuo.com/static/loading.gif)
把AdMob Android SDK(googleadmobadssdkandroid.zip)下載下來。
四、在你的Android應用中加入AdMob SDK
把下載的googleadmobadssdkandroid.zip解壓開你會看到一個GoogleAdMobAdsSdk-6.0.1.jar
把這個文件copy到項目的libs中
![](http://static.javashuo.com/static/loading.gif)
再把它添加到Java Build Path中
![](http://static.javashuo.com/static/loading.gif)
五、添加AdMob配置與佈局
首先在AndroidManifest.xml中加入
01 |
<? xml version = "1.0" encoding = "utf-8" ?> |
02 |
< manifest xmlns:android = "http://schemas.android.com/apk/res/android" |
03 |
package = "org.noahx.scalaandroid" |
04 |
android:versionCode = "1" |
05 |
android:versionName = "1.0" > |
07 |
< uses-sdk android:minSdkVersion = "15" /> |
09 |
< uses-permission android:name = "android.permission.INTERNET" /> |
10 |
< uses-permission android:name = "android.permission.ACCESS_NETWORK_STATE" /> |
13 |
android:icon = "@drawable/ic_launcher" |
14 |
android:label = "@string/app_name" > |
16 |
android:name = ".ScalaAndroidActivity" |
17 |
android:label = "@string/app_name" > |
19 |
< action android:name = "android.intent.action.MAIN" /> |
21 |
< category android:name = "android.intent.category.LAUNCHER" /> |
25 |
android:name = "com.google.ads.AdActivity" |
26 |
android:configChanges = "keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" /> |
a.加入訪問網絡與internet權限
1 |
< uses-permission android:name = "android.permission.INTERNET" /> |
2 |
< uses-permission android:name = "android.permission.ACCESS_NETWORK_STATE" /> |
b.加入AdActivity
2 |
android:name = "com.google.ads.AdActivity" |
3 |
android:configChanges = "keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" /> |
而後layout中加入一個LinearLayout準備放廣告
![](http://static.javashuo.com/static/loading.gif)
六、修改你的主Activity,加入 AdMob代碼
注意//admob註釋爲加入代碼
01 |
package org.noahx.scalaandroid |
03 |
import android.app.Activity |
04 |
import android.os.Bundle |
05 |
import android.widget.Button |
06 |
import android.widget.TextView |
07 |
import android.view.View |
09 |
import android.widget.LinearLayout |
10 |
import com.google.ads.AdView |
11 |
import com.google.ads.AdSize |
12 |
import com.google.ads.AdRequest |
14 |
class ScalaAndroidActivity extends Activity with FindView { |
16 |
lazy val text = findView[TextView](R.id.text 1 ) |
17 |
lazy val button = findView[Button](R.id.button 1 ) |
18 |
lazy val linearLayout = findView[LinearLayout](R.id.linearlayout 1 ) //admob |
20 |
lazy val adView = new AdView( this , AdSize.BANNER, "a14xxxxxxxxxxx" ) //admob |
22 |
override def onCreate(savedInstanceState : Bundle) = { |
23 |
super .onCreate(savedInstanceState) |
25 |
setContentView(R.layout.main) |
27 |
button.onClick { view : View = > |
28 |
text.setText( "hello scala1!!!" ) |
31 |
linearLayout.addView(adView) //admob |
32 |
adView.loadAd( new AdRequest()) //admob |
35 |
override def onDestroy() = { |
36 |
if (adView ! = null ) { //admob |
37 |
adView.destroy() //admob |
注意a14xxxxxxxxxxx,這個ID在如下頁面查看
進入Sites&Apps中Sites&Apps,在下面找到你建的test1這個app。點(Manage Settings)就能夠打開如下頁面
![](http://static.javashuo.com/static/loading.gif)
Publisher ID就是在new AdView的最後的參數。
七、運行效果
![](http://static.javashuo.com/static/loading.gif)
八、看看咱們的午餐錢
注意統計有延時
![](http://static.javashuo.com/static/loading.gif)