Android开发步步为营之55:google广告平台admob接入总结
来源:互联网 发布:人工智能的成功案例 编辑:程序博客网 时间:2024/06/01 08:14
App变现的主要渠道有广告,增值服务,在线交易。最近项目需要接入google的admob广告平台,这里写个总结,方便其他开发者参考。
第一步:通过android sdk manager下载google play services lib,如何下载不了,baidu一下,去下载其他人提供的
下载好了之后,将该lib项目引用到测试项目study,即可调用google play services相关广告的api了
第二步、https://www.google.com/admob/ 注册账号,注册完成之后,就可以创建新应用获利了,我这里测试已经有$0.13了
注意创建的广告单元id,接下来我们要用到
第三步:AndroidManifest.xml添加权限、meta-data、Adactivity
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.android.gms.example.bannerexample" > <!-- Include required permissions for Google Mobile Ads to run--> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <!--This meta-data tag is required to use Google Play Services.--> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <activity android:name="com.figo.study.AdmobActivity" android:theme="@android:style/Theme.NoTitleBar" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!--Include the AdActivity configChanges and theme. --> <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:theme="@android:style/Theme.Translucent" /> </application></manifest>
第四步:设计测试页面
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <com.google.android.gms.ads.AdView android:id="@+id/adView" android:layout_width="match_parent" android:layout_height="wrap_content" ads:adSize="SMART_BANNER" ads:adUnitId="@string/banner_ad_unit_id" > </com.google.android.gms.ads.AdView></LinearLayout>这里的banner_ad_unit_id即为admob中创建应用的广告单元id,配置在了res/values/strings.xml文件中
<string name="banner_ad_unit_id">ca-app-pub-2128163432248238/6211350109</string>
第五步:Activity中调用
* */package com.figo.study;import android.app.Activity;import android.os.Bundle;import com.google.android.gms.ads.AdRequest;import com.google.android.gms.ads.AdView;/** * @author figo * */public class AdmobActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.activity_admob);try {// 横幅广告AdView mAdView = (AdView) findViewById(R.id.adView);AdRequest adRequest = new AdRequest.Builder().build();// mAdView.setAdSize(AdSize.FULL_BANNER);mAdView.loadAd(adRequest);// 插页式广告// final InterstitialAd interstitial = new InterstitialAd(// AdmobActivity.this);// interstitial.setAdUnitId(getString(R.string.banner_ad_unit_id));// if (interstitial.isLoaded()) {// interstitial.show();//// } else {// AdRequest adRequest = new AdRequest.Builder().build();// interstitial.loadAd(adRequest);// AdListener adListener = new AdListener() {//// @Override// public void onAdLoaded() {// // TODO Auto-generated method stub// super.onAdLoaded();// interstitial.show();// }// };// interstitial.setAdListener(adListener);// }} catch (Exception e) {System.out.print(e.getStackTrace());}}}
OK,大功告成,运行效果:
顺便提供一下google admob官方接入文档
AdMob网址:https://apps.admob.com
Admob开参考文档:https://developers.google.com/mobile-ads-sdk/
快速入门:https://developers.google.com/mobile-ads-sdk/docs/admob/android/quick-start
SDK下载: https://developers.google.com/mobile-ads-sdk/download
Admob参考demo下载:https://github.com/googleads/googleads-mobile-android-examples
FROM: http://www.it165.net/pro/html/201504/39322.html
- android开发步步为营之55:google广告平台admob接入总结
- Android开发步步为营之55:google广告平台admob接入总结
- android开发步步为营之68:Facebook原生广告接入总结
- android开发步步为营之70:android接入Google Analytics总结
- Android Google广告开发 Firebase、AdMob
- 关于接入google admob广告系统
- Google Admob广告Android攻略
- Android google play admob 广告
- android开发基于cocos2dx加入google admob广告方法
- Unity3d接入Admob广告教程android篇
- android添加广告之--admob
- android添加广告之--admob
- 第三方广告平台admob聚合接入过程
- Google Admob广告Android 、简单应用
- google admob 广告插件添加[android]
- Android平台给PhoneGap添加Admob广告
- Android平台给cordova添加Admob广告
- Google AdMob 广告使用
- 字典(trie)树的应用与实现
- 编码问题
- cookie与session简单介绍
- LeetCode小试
- Github中Watch 和 Star 的区别
- Android开发步步为营之55:google广告平台admob接入总结
- HDU 2955 Robberies
- Spring 系列: Spring 框架简介
- C++学习笔记(四)
- 手机适配----资源适配篇(values)
- Process and Thread Functions--进程线程函数
- 通过二维码传输少量文本文件
- C语言的类型转化
- U盘安装win7+CentOS6.3双系统