開始Admob廣告盈利模式詳細教程

花了整整一天時間,研究怎麼通過在Android應用程序中添加Admob廣告來賺錢。網上也有些教程,不過說得不夠詳細,自己還得花時間摸索。爲了讓後來者能更快開始Admob廣告賺錢,所以寫個詳細一點的教程,供大家參考。


        例子工程源碼下載地址:     下載源代碼
       
        當然,我也參考了一些網上的資料,主要有:

        AdMob:在android應用中嵌入廣告的方案
        如何在Android Market賺錢 part 2 - 免費app附帶廣告
        Publisher Starter Kit
        面向開發者 Wiki 的 AdMob


        好了,現在讓我從頭開始說起……在這之前,你不需要有任何的帳號,唯一需要的就是有一個有效的email郵箱。只要按照下面的步驟一步步來,你就能通過將Admob的廣告插到自己的程序中賺錢啦!


        首先,當然是需要註冊一個Admob的帳號。Admob的主頁是:http://www.admob.com/ 。 當然,如果你對於瀏覽英文網頁還有些障礙的話,可以登錄中文網站:http://zhcn.admob.com/ 。如果網站的文字還是英文,你可以在網站主頁的右下角的“Language”處,選擇“中文(簡體)”。點擊進入註冊頁面後,有一些欄目需要填寫,不要太過疑慮,就像你註冊一個論壇一樣,隨便填下就好了。最關鍵的是保證填寫的email地址有效,另外就是填上姓名,選擇語言。帳戶類型我選擇的“不確定”,語言“中文(簡體)”~ 提交註冊申請之後,不久你就會收到用於確認並激活帳號的電子郵件,點擊激活鏈接,就可以了激活你的Admob帳號了~


        第二步就是設置你的Android應用程序信息,並獲得Admob的插入代碼登錄你的Admob帳號後,在主頁的左上方(Logo上面)點擊“Marketplace(手機廣告市場)”,進入頁面後,在“Sites&Apps(站點和應用程序)”標籤下,點擊“Add Site/App”。選擇我們熟悉的圖標——" Android App ” 。這時會出現需要你填寫一個“詳細信息”,隨便填上一些信息。(不要太過在意現在填寫的東西,因爲這些以後都是可以修改的)。比如“Android Package URL” 我到現在都還沒有填寫,描述之類的,想寫就寫點吧。填好詳細信息後,點擊“繼續”,就可以到AdMob Android SDK 的下載頁面了。下載這個SDK(當然,這個很重要)。

        The AdMob Android SDK includes:

        README: Get started with AdMob Android ads! 
        AdMob Jar file: Required for publishing ads. Follow the documentation in javadoc/index.html and drop the AdMob Jar file into your project. 
        Sample Projects: Examples of AdMob Android ads shown in the LunarLander application.


        第三步獲取你的應用程序對應的Publisher ID。在下載頁面點擊"Go to Sites/Apps"就可以到你應用程序的管理界面了。這時你會發現在這個頁面醒目的位置會有一個叫你填寫詳細信息的提示:

         在我們發送任何有待收入之前,您需要填寫技術聯繫詳細信息和付款首選項

        我們暫時可以不用管它,因爲錢是會存在我們的Admob的賬戶上的,等我們需要提現的時候,或者你想填的時候再填就可以了。在下面的列表中,選擇你的應用程序並進入。這個界面就是你的應用程序廣告的管理界面了,裏面有比較多的功能,以後可以慢慢了解,現在我們只需要知道兩個東西,一個是發佈者 ID(Publisher ID),一個是你程序的狀態。Publisher ID是一個15個字符的字符串,而你程序的狀態現在應該還是不活動(Inactive)。我們下面要做的就是怎麼讓它變爲Active。

第四步代碼編寫——在你的應用程序中插入Admob廣告。經過上面的步驟,我們在網站上的設置就告一個段落了,現在我們終於要進入主題了,如何在自己的Android應用程序中插入Admob廣告。如果你不健忘的話,一定還記得我們之前下載的那個AdMob Android SDK 。解壓它,看看裏面有些什麼東西。這裏面最重要的就是那個名爲“admob-sdk-android.jar”的包啦,Admob將如何把廣告加載到Android應用程序中的代碼集成在這個包裏,我們編寫程序的時候就需要將這個包導入到我們的工程裏面去。另外,解壓出來的文件夾中還有一個名爲“javadoc”的文件夾,打開它裏面的index.html。它是關於Admob Android SDK的幫助文檔,在Package 下的Setup下,有詳細完整的在自己的應用程序中插入廣告的方法介紹,在這裏我就偷懶,引用一下~

        Including the Jar

        Add the Jar file included with the SDK to your Android project as an external library. In your project's root directory create a subdirectory libs (this will already be done for you if you used Android's activitycreator). Copy the AdMob Jar file into that directory. For Eclipse projects:

        Go to the Properties of your project (right-click on your project from the Package Explorer tab and select Properties) 
        Select "Java Build Path" from left panel 
        Select "Libraries" tab from the main window 
        Click on "Add JARs..." 
        Select the JAR copied to the libs directory 
        Click "OK" to add the SDK to your android project

        注意:需要首先在你工程的根目錄下新建一個叫做“libs”的文件夾,並把之前所說的最重要的東西“admob-sdk-android.jar”複製到裏面。


        AndroidManifest.xml

        Your AdMob publisher ID was given to you when creating your publisher account on www.admob.com before downloading this code. It is a 15-character code like a1496ced2842262. Just before the closing </application> tag add a line to set your publisher ID: 

                <!-- The application's publisher ID assigned by AdMob -->
                <meta-data android:value="YOUR_ID_HERE" android:name="ADMOB_PUBLISHER_ID" />
        </application>

        Set any permissions not already included just before the closing </manifest> tag: 

                <!-- AdMob SDK permissions -->
                <uses-permission android:name="android.permission.INTERNET" />
                <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
        </manifest>

        Only the INTERNET permission is required. Setting ACCESS_COARSE_LOCATION (and/or ACCESS_FINE_LOCATION) allows narrowly geo-targeted ads be shown.

        這裏需要注意的是,<meta-data android:value="YOUR_ID_HERE" android:name="ADMOB_PUBLISHER_ID" />中,我們只需要改的是"YOUR_ID_HERE"。這裏需要你填上的ID就是我們之前在Admob網站我們的應用程序管理頁面上看到的Publisher ID,而name="ADMOB_PUBLISHER_ID"是不應該改的。程序需要這個Key來查找對應的Value。


        attrs.xml

        The attrs.xml file specifies custom AdView attributes in XML layout files. If your application does not already have an /res/values/attrs.xml file then create one and copy-and-paste the following into it. If you do have that file then just add the declare-styleable element:


        <?xml version="1.0" encoding="utf-8"?>
        <resources>
                <declare-styleable name="com.admob.android.ads.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" />
                </declare-styleable>
        </resources>

        這個,沒什麼說的。


        Placing an AdView in a Layout

        AdView widgets can be put into any XML layout now. The first step is to reference attrs.xml in your layout element by adding an xmlns line that includes your package name specified in AndroidManifest.xml: 

        xmlns:yourapp=http://schemas.android.com/apk/res/yourpackage

        For example a simple screen with only an ad on it would look like: 

        <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout 
                xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:admobsdk="http://schemas.android.com/apk/res/com.admob.android.example"
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
    
                <com.admob.android.ads.AdView  
                        android:id="@+id/ad" 
                        android:layout_width="fill_parent" 
                        android:layout_height="wrap_content"
                        admobsdk:backgroundColor="#000000"
                        admobsdk:textColor="#FFFFFF"
                        admobsdk:keywords="Android application"
                />
                        
        </LinearLayout>

        這裏好像也沒什麼需要特別注意的,注意加上xmlns,另外知道這裏可以設置一個keywords。


        Test Mode

        When you start integrating AdMob ads into your application it is recommended to use test mode. This always returns the same ad. Normal ad requests are not deterministic making it harder to be sure the ad view looks like you want (e.g. ad requests can timeout or may not fill). 

        
Once the ad shows up as you expect be sure to turn test mode off to get real ads. Never put your application into the Android Market with test mode enabled.

         Test mode can be enabled either by calling AdManager.setInTestMode(true) or by adding a "admobsdk:testing="true"" property to the ad in your XML layout (where "admobsdk" is the XML namespace for your application).


        設置Test Mode這個很關鍵,千萬別將處於Test Mode的程序發佈出去了,那樣可賺不了錢啊~!如果在AdView的屬性中不加上admobsdk:testing="false",似乎程序也是不處於Test Mode的,不過最好還是加上吧~


        第五步編譯運行,並激活程序。編譯運行你的程序,在模擬器上就可以看到效果啦~(當然你的模擬器需要能上網,關於怎麼讓模擬器上網呢?用路由的應該可以直接上,如果不是用路由,那麼可能需要設置下,具體方法大家自己網上搜吧,具體忘了)。如果你的應用程序能顯示出廣告,那麼恭喜你,你的應用程序很快就會在Admob上被激活了(需要一定的時間,我的好像花了一個小時不到)!


        第六步在Admob網站上查看應用程序賺了多少錢~“手機廣告市場”—>“報告”—>“站點和應用程序報告”。選擇你的應用程序,然後點擊頁面最下面的“創建報告”~ OK,賺錢啦~

最後,我把我自己寫的一個例子工程上傳上來,大家可以下載來參考下。另外,我的工程將廣告作爲移動的,並且改變了它默認的寬度和背景,希望對如何在應用程序中擺放廣告,起到一個拋磚引玉的作用。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章