[l轉]在Android中嵌入AdMob廣告,賺午餐錢

長話短說,我喜歡比較直接的方式,好讓咱們開始吧!android

AdMob(現被Google收購)提供了移動設備加入廣告接口,並會分給發佈者必定的經濟利潤。程序員

對於Android程序員來講,午餐錢是有了。網絡

一、註冊AdMob

訪問http://www.admob.comapp

點擊這個連接ide

若是你有Google帳戶就好辦了,直接選Sign in With your Google Account佈局

而後輸入Google的Password就能夠登陸了ui

填寫基本帳戶信息,這個不關鍵,不是付款信息,Account Type選Publisherthis

而後完善付款信息google

注意用英文填寫,以上爲招商銀行的例子。(我也是剛用,不保證能夠收到匯款)。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

打開後選擇Android App,輸入應用的一些基本信息

三、下載AdMob Android SDK

成功建立後會看到

把AdMob Android SDK(googleadmobadssdkandroid.zip)下載下來。

四、在你的Android應用中加入AdMob SDK

把下載的googleadmobadssdkandroid.zip解壓開你會看到一個GoogleAdMobAdsSdk-6.0.1.jar

把這個文件copy到項目的libs中

再把它添加到Java Build Path中

五、添加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" >
06  
07     <uses-sdk android:minSdkVersion="15" />
08  
09     <uses-permission android:name="android.permission.INTERNET" />
10     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
11  
12     <application
13         android:icon="@drawable/ic_launcher"
14         android:label="@string/app_name" >
15         <activity
16             android:name=".ScalaAndroidActivity"
17             android:label="@string/app_name" >
18             <intent-filter>
19                 <action android:name="android.intent.action.MAIN" />
20  
21                 <category android:name="android.intent.category.LAUNCHER" />
22             </intent-filter>
23         </activity>
24         <activity
25             android:name="com.google.ads.AdActivity"
26             android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
27     </application>
28  
29 </manifest>

a.加入訪問網絡與internet權限

1 <uses-permission android:name="android.permission.INTERNET" />
2 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

b.加入AdActivity

1 <activity
2            android:name="com.google.ads.AdActivity"
3            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

而後layout中加入一個LinearLayout準備放廣告

六、修改你的主Activity,加入 AdMob代碼

注意//admob註釋爲加入代碼

01 package org.noahx.scalaandroid
02  
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
08 import FindView._
09 import android.widget.LinearLayout
10 import com.google.ads.AdView
11 import com.google.ads.AdSize
12 import com.google.ads.AdRequest
13  
14 class ScalaAndroidActivity extends Activity with FindView {
15  
16   lazy val text = findView[TextView](R.id.text1)
17   lazy val button = findView[Button](R.id.button1)
18   lazy val linearLayout = findView[LinearLayout](R.id.linearlayout1)      //admob
19  
20   lazy val adView = new AdView(this, AdSize.BANNER, "a14xxxxxxxxxxx")     //admob
21  
22   override def onCreate(savedInstanceState: Bundle) = {
23     super.onCreate(savedInstanceState)
24  
25     setContentView(R.layout.main)
26  
27     button.onClick { view: View =>
28       text.setText("hello scala1!!!")
29     }
30  
31     linearLayout.addView(adView)       //admob
32     adView.loadAd(new AdRequest())     //admob
33   }
34  
35   override def onDestroy() = {
36     if (adView != null) {              //admob
37       adView.destroy()                 //admob
38     }                                  //admob
39     super.onDestroy()
40   }
41 }

注意a14xxxxxxxxxxx,這個ID在如下頁面查看

進入Sites&Apps中Sites&Apps,在下面找到你建的test1這個app。點(Manage Settings)就能夠打開如下頁面


Publisher ID就是在new AdView的最後的參數。

七、運行效果

八、看看咱們的午餐錢

注意統計有延時

相關文章
相關標籤/搜索