Application to the sea--AdMob

Introduction

Google AdMob is currently the world's largest mobile APP advertising platform. It is open to application developers and advertisers who need to advertise in applications, providing solutions for exploring business opportunities, building brands and realizing revenue on the mobile terminal.

It’s actually a platform for displaying ads in apps, game pages, and web pages.

Ad type difference

Banner ads
occupies a small area, loaded with AdView, and implemented internally by webView. After loading, it will automatically advertise, click to jump to the corresponding market or webpage.
banner ad
Interstitial Ads The ads
displayed in full screen, which may be pictures or videos. Inside is a webview rewarded
Insert picture description here
video advertisement. It
occupies the full screen and plays a video. The reward time point and reward value can be configured in the background, and the callback can be received during monitoring to perform corresponding business processing. Generally used in scenarios such as virtual currency rewards and video unlocking. It is also a webview that implements
Insert picture description here
native ads
. The difference from the previous few is that this type of ad request will not automatically load after a successful request, but will return the advertising information to the developer, who defines how the layout should display the advertising content.
In the background of the advertising content, one or both of the video and pictures can be selected.
Insert picture description here

Access

There are not too many problems with access, follow the official website document step by step to access.
Official website access document -> document address

  1. Via gradle or jar packageImport sdk
  2. Apply for application (package name), apply for ad unit,Generate unitId, Each advertisement displayed needs to correspond to a unitId. Of course, the same id can also be used, but it is impossible to distinguish the click-through rate and revenue from advertisements in specific locations.
  3. Old version: in Applicationinitialization(Use appId). New version: Configure in AndroidManifest.xml
  4. Set up advertising display clothBureau (xml configuration or java generation). Note: Banner advertisement: unitId and AdSize must be set in xml or code at the same time, size cannot be set in xml, unitId is set in code.
  5. Set unitId,Request ad
  6. Show ads
  7. monitorRequired events (load failure, success, click, close, jump, etc.)

important point

The loading of native ads does not automatically load, but there is no detailed document explaining the meaning of each field, or how to get the click event, how to jump, etc., you can refer to the official demo:
refer to the demo address

Pit guide

Because it is more popular in foreign countries, there are not many people who accept this library in China, and there are still quite a few pits slowly stepping on it.

一、Failed to load , errorCode = 3

There are quite a few encounters with this problem. There are roughly two reasons:

  1. Unit id just registered
  2. The request is successful, but there is not enough inventory to return

I also encountered that because the mobile phone didn't turn over the wall, the code was returned to 3. It displayed normal immediately after turning over the wall, but it clearly said that it can be obtained without turning over the wall. . . . . .

In addition, corresponding to the errCode in the onLoadFailed method, the official website has a document describing it, and you can find the corresponding cause according to the document.
Link—> Corresponding code encoding
Examples are as follows:

Type Code Reason
int ERROR_CODE_NO_FILL The ad request was successful, but no ad was returned due to lack of ad inventory.
int ERROR_CODE_INTERNAL_ERROR Something happened internally; for instance, an invalid response was received from the ad server.

It
feels really no solution to solve this problem. At first, I worked on this problem for half a month. I tested the unitId and everything was normal. It was an error when I cut it into the official id. I read various documents and found no results. Later, I made a plan B and went online. Just go online and the ads load normally. . .

Two, AdView does not display after loading successfully

I encountered a problem that the banner ad was not displayed. I thought it was a failure to load. Through monitoring, it was found that the loading was successful, but it was not displayed.
Reason 1
When googlePlay Service encounters ADMob, after a fierce collision, such a bug will be concluded. After the AdView is loaded, the display cannot be automatically refreshed. You need to wait for it to redraw the next time. This time is 60s, so the resource acquisition is successful. Is not displayed.
In the case of this problem, the way to import admob is api 'com.google.android.gms.play-services-ads:8.1.0', if you change to the admob library to import separately instead of importing through play-services, there will be no such problem.
Solution: In the callback method onLoadAd(), manually trigger the redraw. Such as setBackground(), layout() and other methods

Reason 2 In the
actual development, there is a situation that is related to the setting of AdSize, which causes the load to be successfully but not displayed.
In the official website document, there is a description of the display abnormality caused by the incorrect setting of AdSize:

Note: The size of the banner ad container must be at least as large as the banner ad. If your container has inner margins, it will effectively reduce the container size. If the container cannot accommodate the banner ad, the banner ad will not be displayed and the following warning will appear in your log:
W/Ads: Not enough space to show ad. Needs 320x50 dp, but only has 288x495 dp.

The official website has a type of AdSize called SMART_BANNER. The official website describes it as intelligently adapting to vertical, horizontal, and large screens to adaptively change the width and height. So smart, I set it to this size. The result is often not loaded and cannot be displayed. Replace it with Immediately after BANNER, it shows normal.
Solution: Try to use the official Size, if you set the width and height yourself, be careful to be able to accommodate the advertisement

Three, native advertising video related

If native ads are selected in the background, there are two types of ads that can be checked:

  • image
  • film

Playback monitoring In
many scenarios, products will propose to use video advertisements. After watching something to the user or unlocking a certain content, you need to use monitoring, while the video playback monitoring in native ads is different. We need the following settings:

After obtaining the NativeAD object, obtain the VideoController object, and monitor through this:

VideoController vc = nativeAd.getVideoController();
vc.setVideoLifecycleCallbacks(new VideoController.VideoLifecycleCallbacks() {
    @Override
    public void onVideoPlay() {
        super.onVideoPlay();
        isStartPlay = true;
    }

    @Override
    public void onVideoEnd() {
        super.onVideoEnd();
        isPlayEnd = true;
    }
    //其他回调方法
    ...
});

Play settings
Regarding whether to play in silence, you can configure as follows

VideoOptions videoOptions = new VideoOptions.Builder()
        //设置不静音播放,默认静音
        .setStartMuted(false)
        //设置是否点击展开全屏,默认否
        .setClickToExpandRequested(true)
        .build();

Finally, in the process of building AdLoader, add Options:

.withNativeAdOptions(new NativeAdOptions.Builder()
        //设置的配置
        .setVideoOptions(videoOptions)
        .build())
.build()

Advertising source problem
If you only check videos in the background, and you want to realize that they are all video advertisements, then you will get a lot of trouble . Because it still exposes a lot of image ads. .
Possible reason 1: There is a problem with the filtering of google, and it is useless to check it

Possible reason 2: The advertiser may clearly be a picture when it is placed, and it must be cast under the video type, and then the life and death we load are just pictures

4. Fill in slowly in the future

Guess you like

Origin blog.csdn.net/lizebin_bin/article/details/89710358