Android Google AdMob AD Access sample

Source: Internet
Author: User
Tags firebase analytics admob

Android Google AdMob AD Access sample

[TOC]

First of all, please rest assured that, although Google search and other services have been Qiang, but advertising services can be used at home, is really a celebration AH ~ ~ ~ Poof!

In fact, this article is only a record of my access to AdMob process, more specific in fact, the official Google to more detailed (map and video and GitHub demo sample, etc.), so do not want to see the official (after all, most of the English) can read I write, if you have read the official or have learned to focus on my * * The location of the bold * *, so that you quickly find the information you want.

Google Official Guide: HTTPS://FIREBASE.GOOGLE.COM/DOCS/ADMOB/?HL=ZH-CN

0. What is AdMob?

AdMob by Google is a mobile advertising platform that allows you to earn significant revenue from your app. By combining AdMob with Firebase analytics, you can not only get more application usage data, but also improve your analytical capabilities. Without changing your existing AdMob configuration, Firebase can be integrated with AdMob.

1. What are the types of AdMob ads?

There are four kinds of total.
They are:Banner (Banner ad ),interstitial (interstitial),rewarded Video (in-app purchase ads),Native (native ads).

    • Banner (Banner AD): The most common is the screen usually seen at the bottom or at the top of a horizontal bar of the banner.
    • Interstitial (inset AD): Similar to the start Page ad, the entire screen displays an ad.
    • Rewarded video (in-app purchase ads): This play foreign game often see, you watch an advertising video, the game will reward you some props or other what ( this bonus is an integer, you can set the number in AdMob, the user watching the video will get this amount of reward, such as reward 3 bottles of potions, 3 life and so on. ).
    • Native (native AD): This is the best form of advertising, seamless with the native app, and maybe you've seen a list of items that show ads, that's the form.
2. Take Banner advertising as an example, Access admob2-1. Account

you need a Google account , then sign up for AdMob, and if you have a Google account you can sign in directly.
You can't go on until you have an account!

NOTICE: If the AdMob login page does not open (other pages can be opened), be sure to prohibit AdBlock such as blocking ads plug-ins, or manually add white list!!!

2-2. Create a new project on AdMob

It is recommended that you write the official Google example again, no trouble.

Create a new project on AdMob, https://apps.admob.com/, the middle prompts you to fill in the package name, project name, etc. , truthfully fill it out.

Your interface should look like this at the end of the completion:

Watch your and APP id ,ad unit id, download the google-service.json configuration file.

2-3. Android Studio Project configuration

Configure Gradle

1. Project-level Build.gradle

    dependencies {        classpath ‘com.android.tools.build:gradle:x.x.x‘        classpath ‘com.google.gms:google-services:3.0.0‘    }

2. Application-level Build.gradle

...    dependencies {            compile fileTree(dir: ‘libs‘, include: [‘*.jar‘])            compile ‘com.android.support:appcompat-v7:xx.x.x‘            compile ‘com.google.firebase:firebase-ads:10.2.1‘        }...//apply plugin 语句位于底部apply plugin: ‘com.google.gms.google-services‘

3.google-service.json

Paste directly at the application-level root directory, for example:Yourproject/app/google-service.json

2-4. Eclipse project configuration

2-5. XML Layout Authoring

Main Page layout:activity_main.xml

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" match_parent "xmlns:ads=" http://schemas.android.com/apk/ Res-auto "android:layout_height=" match_parent "android:paddingleft=" @dimen/activity_horizontal_margin "Android: paddingright= "@dimen/activity_horizontal_margin" android:paddingtop= "@dimen/activity_vertical_margin" Android: paddingbottom= "@dimen/activity_vertical_margin" tools:context= ". Mainactivity "> <textview android:text=" @string/hello_world "android:layout_width=" Wrap_content "Android:la yout_height= "Wrap_content"/> <com.google.android.gms.ads.adview android:id= "@+id/adView" android:l        Ayout_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_centerhorizontal= "true"    Android:layout_alignparentbottom= "true" ads:adsize= "BANNER" ads:adunitid= "@string/banner_ad_unit_id" > &Lt;/com.google.android.gms.ads.adview></relativelayout> 
2-6. Activity Loading Banner Ads

Mainactivity.java part of the code:

package ...import ...import ...import com.google.android.gms.ads.AdRequest;import com.google.android.gms.ads.AdView;public class MainActivity extends ActionBarActivity {    ...    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        //加载广告        AdView mAdView = (AdView) findViewById(R.id.adView);        AdRequest adRequest = new AdRequest.Builder().build();        mAdView.loadAd(adRequest);    }    ...}

Do not forget the main permission to finish:

    <uses-permission android:name="android.permission.INTERNET"/>    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
2-7. Google AdMob Demo Address

Official Demo Address: Https://github.com/googleads/googleads-mobile-android-examples

3.

Show Banner banner at the bottom of the page:

4. Precautions

<: NOTICE:>

When you sign up for your AdMob account, create your project, get the corresponding ID, and prepare for the test, you may get some errors: Failed to load ad 3, or there was a problem getting an ad response. Errorcode:0 and so on.

Note that the project you created takes a while to test, so even though your code and configuration are correct, you still get the error. Wait for a while, I was about 2 hours before normal.

<: NOTICE:> about rewarded Video (in-app purchase ads)

You have a high chance of getting an error when testing----failed to load ad 3, and the method's failure callback responds.

It's just that the system doesn't have any ads to return to you, that is, in-app video ads aren't always there.

The error message can be explained on the official website:

public static final int ERROR_CODE_NO_FILL  --> Constant Value: 3The ad request was successful, but no ad was returned due to lack of ad inventory.广告请求已成功,但由于缺少广告资源,没有返回任何广告。

More error messages can be found on the official website: https://developers.google.com/android/reference/com/google/android/gms/ads/AdRequest

5. Summary

Google's ads heard more intentions, the actual effect does not know how, this article describes the incomplete or future changes are subject to the official website.

Official website: http://www.google.cn/admob/

enjoy!

Android Google AdMob AD Access sample

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.