<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    小菜毛毛技術(shù)分享

    與大家共同成長

      BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
      164 Posts :: 141 Stories :: 94 Comments :: 0 Trackbacks

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

    例子工程源碼下載地址:(建議使用瀏覽器自帶的下載工具下載)http://cid-cb78b387364ae9a7.skydrive.live.com/browse.aspx/.Public/%e8%bd%af%e4%bb%b6/Andoroid
    當然,我也參考了一些網(wǎng)上的資料,主要有:

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

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

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

    第二步就是設(shè)置你的Android應(yīng) 用程序信息,并獲得Admob的插入代碼。登錄你的Admob帳號后,在主頁的左上方(Logo上面)點擊“Marketplace(手機廣告市場)”, 進入頁面后,在“Sites&Apps(站點和應(yīng)用程序)”標簽下,點擊“Add Site/App”。選擇我們熟悉的圖標——" Android App ” 。這時會出現(xiàn)需要你填寫一個“詳細信息”,隨便填上一些信息。(不要太過在意現(xiàn)在填寫的東西,因為這些以后都是可以修改的)。比如“Android Package URL” 我到現(xiàn)在都還沒有填寫,描述之類的,想寫就寫點吧。填好詳細信息后,點擊“繼續(xù)”,就可以到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.

    第三步獲取你的應(yīng)用程序?qū)?yīng)的Publisher ID。在下載頁面點擊"Go to Sites/Apps"就可以到你應(yīng)用程序的管理界面了。這時你會發(fā)現(xiàn)在這個頁面醒目的位置會有一個叫你填寫詳細信息的提示:

    在我們發(fā)送任何有待收入之前,您需要填寫技術(shù)聯(lián)系詳細信息和付款首選項。

    我們暫時可以不用管它,因為錢是會存在我們的Admob的賬戶上的,等我們需要提現(xiàn)的時候,或者你想填的時候再填就可以了。在下面的列表中,選擇你 的應(yīng)用程序并進入。這個界面就是你的應(yīng)用程序廣告的管理界面了,里面有比較多的功能,以后可以慢慢了解,現(xiàn)在我們只需要知道兩個東西,一個是發(fā)布者 ID(Publisher ID),一個是你程序的狀態(tài)。Publisher ID是一個15個字符的字符串,而你程序的狀態(tài)現(xiàn)在應(yīng)該還是不活動(Inactive)。我們下面要做的就是怎么讓它變?yōu)锳ctive。

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


    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”復(fù)制到里面。


    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網(wǎng)站我們的應(yīng)用程序管理頁面上看到的 Publisher ID,而name="ADMOB_PUBLISHER_ID"是不應(yīng)該改的。程序需要這個Key來查找對應(yīng)的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,另外知道這里可以設(shè)置一個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).


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

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

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

    最后,我把我自己寫的一個例子工程上傳上來,大家可以下載來參考下。另外,我的工程將廣告作為移動的,并且改變了它默認的寬度和背景,希望對如何在應(yīng)用程序中擺放廣告,起到一個拋磚引玉的作用。效果圖如下(哈哈,在模擬器跑的~):



    1.http://www.admob.com/注冊一個帳號,

    添加Add Mobile Site/app,輸入相關(guān)信息后,提交完成,

    下載Android平臺使用的JAR,查看發(fā)布者 ID。

    2.然后將JAR添加到你的項目中

    Properties->Java Build Path->Libraries->Add JARs…->Select the JAR->OK

    3.編輯AndroidManifest.xml

    application節(jié)點中添加

    <!– The application’s publisher ID assigned by AdMob –>

    <meta-data android:value=”a14ae1ce0357305″ android:name=”ADMOB_PUBLISHER_ID” />

    manifest節(jié)點添加權(quán)限申請

    <!– AdMob SDK permissions –>

    <uses-permission android:name=”android.permission.INTERNET” />

    4.添加attrs.xml

    /res/values/attrs.xml

    <?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>

    5.添加廣告組件

    <?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.moandroid.livesports”

    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:text=”@string/hello”

    />

    <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”

    admobsdk:refreshInterval=”60″

    />

    </LinearLayout>

    6.顯示效果

    為免費app嵌入Admob廣告,進而獲得廣告收入。

    adm

    posted on 2010-12-10 17:42 小菜毛毛 閱讀(2520) 評論(2)  編輯  收藏 所屬分類: andriod

    Feedback

    # re: Android中添加Admob廣告(轉(zhuǎn) 2011-06-24 10:42 楊鑫
    我想問下,在虛擬機里面可以把廣告顯示出來,我測試在手機上就不顯示了呢?  回復(fù)  更多評論
      

    # re: Android中添加Admob廣告(轉(zhuǎn) 2011-06-24 10:43 楊鑫
    @楊鑫
    看到麻煩給我說下:QQ:262431920  回復(fù)  更多評論
      

    主站蜘蛛池模板: 中文字幕影片免费在线观看| 两个人看的www视频免费完整版| 日本一区午夜艳熟免费| 午夜国产大片免费观看| 亚洲色欲色欱wwW在线| 搡女人真爽免费视频大全| 亚洲日韩国产精品无码av| 久草免费福利视频| 久久夜色精品国产嚕嚕亚洲av| 一个人免费观看www视频| 亚洲国产综合久久天堂| 日本高清不卡中文字幕免费| 亚洲国产高清在线一区二区三区 | 亚洲综合精品第一页| 日韩精品无码区免费专区| 7777久久亚洲中文字幕| 日产乱码一卡二卡三免费| 成年免费a级毛片| 亚洲精品成人网久久久久久| 青柠影视在线观看免费高清| 亚洲国产天堂久久综合网站| 成人免费大片免费观看网站| 亚洲乱码无人区卡1卡2卡3| 国产嫩草影院精品免费网址| www永久免费视频| 亚洲成A∨人片在线观看不卡 | 青苹果乐园免费高清在线| 亚洲中文无码永久免| 亚洲精品综合久久| 国产高清不卡免费视频| 精品日韩99亚洲的在线发布| 免费在线观看黄色毛片| 无码专区AAAAAA免费视频| 亚洲一区二区三区高清视频| 一级毛片直播亚洲| 午夜精品射精入后重之免费观看| 精品亚洲国产成人| 亚洲国产精品成人AV无码久久综合影院 | 春意影院午夜爽爽爽免费| 亚洲AV无码国产丝袜在线观看| 无码国产精品一区二区免费I6|