TShopping

 找回密碼
 註冊
搜索
查看: 1633|回復: 0

[教學] AdMob廣告實作

[複製鏈接]
發表於 2014-6-11 21:21:03 | 顯示全部樓層 |閱讀模式
 
Push to Facebook
1.jpg
1.將下載的AdMob SDK解壓縮,將該SDK的JAR檔案路徑加入到應用程式內

2.manifest檔案內設定INTERNET與ACCESS_NETWORK_STATE uses permissions,並宣告com.google.ads.AdActivity與設定configChanges屬性
  1. <uses-permission android:name="android.permission.INTERNET"/>
  2. <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

  3. <activity android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:name="com.google.ads.AdActivity"></activity>
複製代碼
3.在layout檔案內新增AdView元件
adSize:設定廣告看板的尺寸
adUnitId:填入發佈商ID。
loadAdOnCreate:是否一開始就載入廣告。
testDevices:設定測試用的裝置;如果是實機則必須輸入實機的ID,就是IMEI碼
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent"
  6. android:orientation="vertical" >

  7. <TextView
  8. android:id="@+id/textView1"
  9. android:layout_width="wrap_content"
  10. android:layout_height="wrap_content"
  11. android:text="Admob廣告輪播"
  12. android:textSize="20sp" />
  13. <com.google.ads.AdView
  14. android:id="@+id/adView"
  15. android:layout_width="wrap_content"
  16. android:layout_height="wrap_content"
  17. ads:adSize="BANNER"
  18. ads:adUnitId="a1521ffbba6766b"
  19. ads:loadAdOnCreate="true"
  20. ads:testDevices="TEST_EMULATOR" />

  21. </LinearLayout>
複製代碼
4.在程式中加上
  1. AdView adView= (AdView)findViewById(R.id.adView);
  2. adView.loadAd(new AdRequest());
複製代碼

 

臉書網友討論
*滑块验证:
您需要登錄後才可以回帖 登錄 | 註冊 |

本版積分規則



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2024-3-29 08:42 , Processed in 0.069388 second(s), 26 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表