android个人开发者接广告admob以及需要注意的错误细节,android用adb命令打开开发者模式-ESG跨境

android个人开发者接广告admob以及需要注意的错误细节,android用adb命令打开开发者模式

来源网络
来源网络
2022-05-31
点赞icon 0
查看icon 670

android个人开发者接广告admob以及需要注意的错误细节,android用adb命令打开开发者模式android个人开发者接广告admob以及需要注意的错误细节各位知道其他路子的求分享啊,我实在想不到什么方法了,可惜谷歌被屏蔽了,但是总比不能赚1毛钱好。我相信我的粉丝都是极客。注册admobhttps://app......

android个人开发者接广告admob以及需要注意的错误细节,android用adb命令打开开发者模式




android个人开发者接广告admob以及需要注意的错误细节

各位知道其他路子的求分享啊,我实在想不到什么方法了,可惜谷歌被屏蔽了,但是总比不能赚1毛钱好。我相信我的粉丝都是极客。

注册admob

https://apps.admob.com

快速开始教程

https://developers.google.com/admob/android/quickstart hl=zhCN

创建应用

创建banner

得到YOUR_ADMOB_APP_ID

https://developers.google.com/admob/android/quickstart?hl=zhCN#import_the_mobile_ads_sdk

添加xml代码

   android:id=@+id/ad_view

    android:layout_width=match_parent

    android:layout_height=wrap_content

    android:layout_centerHorizontal=true

    android:layout_alignParentBottom=true

    ads:adSize=BANNER

    ads:adUnitId=caapppub6391307239504132/6102840431 /

添加java代码

package ...

import ...

import com.google.android.gms.ads.MobileAds;

public class MainActivity extends AppCompatActivity {

  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

//全局appid

MobileAds.initialize(this, caapppub6391307239504132~6124388718);

//    MobileAds.initialize(this, caapppub3940256099942544~3347511713);

    adView = findViewById(R.id.ad_view);

    // 建立发快递广告请求

    AdRequest adRequest = new AdRequest.Builder()

        .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)

        .build();

    // 添加广告监听.

    adView.setAdListener(new AdListener(){

      @Override

      public void onAdFailedToLoad(int i) {

        Log.w(TAG,load fail :+i);

      }

    });

//加载请求

    adView.loadAd(adRequest);  }

}

}

横幅实现的官方教程在这里

https://developers.google.com/admob/android/banner?hl=zhCN

或者用代码添加banner的方法

adView adView = new AdView(this);

adView.setAdSize(AdSize.BANNER);

adView.setAdUnitId(caapppub6391307239504132/6102840431);

规范细节

不要忘记代理一下声明周期。

  /** Called when returning to the activity */

  @Override

  public void onResume() {

    super.onResume();

    if (adView != null) {

      adView.resume();

    }

  }

  /** Called before the activity is destroyed */

  @Override

  public void onDestroy() {

    if (adView != null) {

      adView.destroy();

    }

    super.onDestroy();

  }

各位测试没效果的可以先直接把我的代码copy测试效果如何。

插屏广告

InterstitialAd mInterstitialAd = new InterstitialAd(this);//插页广告

    mInterstitialAd.setAdUnitId(xxxxx);

激励广告

    RewardedVideoAd mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);

    mRewardedVideoAd.setRewardedVideoAdListener(this);

    mRewardedVideoAd.loadAd(caapppub6391307239504132/8306864775, new AdRequest.Builder().build());

    AdLoader adLoader = new AdLoader.Builder(this, caapppub3940256099942544/2247696110)

        .forAppInstallAd(new NativeAppInstallAd.OnAppInstallAdLoadedListener() {

          @Override

          public void onAppInstallAdLoaded(NativeAppInstallAd appInstallAd) {

            // Show the app install ad.

          }

        })

        .forContentAd(new NativeContentAd.OnContentAdLoadedListener() {

          @Override

          public void onContentAdLoaded(NativeContentAd contentAd) {

            // Show the content ad.

          }

        })

        .withAdListener(new AdListener() {

          @Override

          public void onAdFailedToLoad(int errorCode) {

            // Handle the failure by logging, altering the UI, and so on.

          }

        })

        .withNativeAdOptions(new NativeAdOptions.Builder()

            // Methods in the NativeAdOptions.Builder class can be

            // used here to specify individual options settings.

            .build())

        .build();

    adLoader.loadAd(new AdRequest.Builder().build());

原生广告

说实话原生广告的,老美的文档根本不全,有点乱,根本不知道某个东西如何来的。比如

  private void displayAppInstallAd(ViewGroup parent,NativeAppInstallAd ad) {

    // Inflate a layout and add it to the parent ViewGroup.

    LayoutInflater inflater = (LayoutInflater) parent.getContext()

        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    NativeAppInstallAdView adView = (NativeAppInstallAdView) inflater

        .inflate(R.layout.my_ad_layout, parent);

    // Locate the view that will hold the headline, set its text, and call the

    // NativeAppInstallAdViews setHeadlineView method to register it.

    TextView headlineView = adView.findViewById(R.id.ad_headline);

    headlineView.setText(ad.getHeadline());

    adView.setHeadlineView(headlineView);

    // Repeat the above process for the other assets in the NativeAppInstallAd

    // If the app is using a MediaView to display video, it should be

    // instantiated and passed to setMediaView. This view is a little different

    // in that the asset is populated automatically, so theres one less step.

    MediaView mediaView = (MediaView) adView.findViewById(R.id.ad_media);

    adView.setMediaView(mediaView);

    // Call the NativeAppInstallAdViews setNativeAd method to register the

    // NativeAdObject.

    adView.setNativeAd(ad);

    // Place the AdView into the parent.

    parent.addView(adView);

  }

这里需要传递一个参数,文档并没有说是怎么出来的,我感觉需要找找他们的demo.

https://developers.google.com/admob/android/nativeadvanced?hl=zhCN

https://apps.admob.com/v2/home

将 Firebase 添加到您的 Android 项目

https://firebase.google.com/docs/android/setup

buildscript {

  // ...

  dependencies {

    // ...

    classpath com.google.gms:googleservices:3.2.0 // googleservices plugin

  }

}

allprojects {

  // ...

  repositories {

    // ...

    maven {

      url https://maven.google.com // Googles Maven repository

    }

  }

}

完整步骤

1.请使用此应用 ID 完成说明:

2.请集成 SDK。在使用此广告单元 ID 集成代码时,您需要指定广告类型和展示位置:

3.请开始从 Firebase 控制台下载配置文件。在下一步的最后,您将需要用到此文件。如果您无法访问 Firebase 控制台,请与 Firebase 项目负责人联系,请其将您添加为项目成员。

4.在您的应用中实施 Firebase SDK。

5.完成集成后,请重新发布您的应用,我们会在应用概览信息中心显示相关的分析数据。

6.请查看 AdMob 政策,确保您的实现方案符合相关规定。

排错

on failed for task :childgit:app:processDebugGoogleServices.

File googleservices.json is missing. The Google Services Plugin cannot function without it.

Searched Location:

F:\src\git_project\qq_qqrobot\childgit\app\src\nullnull\debug\googleservices.json

F:\src\git_project\qq_qqrobot\childgit\app\src\debug\nullnull\googleservices.json

F:\src\git_project\qq_qqrobot\childgit\app\src\null

All firebase libraries must be either above or below 14.0.0

fix

  //https://dl.google.com/dl/android/maven2/index.html

implementation com.google.android.gms:playservicesads:15.0.0

  // implementation com.google.android.gms:playservicesads:12.0.1

  //implementation com.google.firebase:firebasecore:11.8.0

    implementation com.google.firebase:firebasecore:15.0.0

进入控制台点击firexx 然后点击下载配置文件。放到这个目录

https://developers.google.com/android/reference/com/google/android/gms/ads/AdRequest

最终

   classpath com.google.gms:googleservices:3.2.1 // googleservices plugin

错误码

我刚开始的时候是0

public final class AdRequest {

  public static final int ERROR_CODE_INTERNAL_ERROR = 0;

  public static final int ERROR_CODE_INVALID_REQUEST = 1;

  public static final int ERROR_CODE_NETWORK_ERROR = 2;

  public static final int ERROR_CODE_NO_FILL = 3;

https://github.com/googleads/googleadsmobileandroidexamples

遇到问题可以提交到谷歌官方的论坛哈

https://groups.google.com/forum/#!forum/googleadmobadssdk

我现在官方的demo正常显示,强烈建议大家也下载demo玩,其实看文档是很不全的。demo的演示比较全,我这里就只给大家做个导师了,哈哈,

我这里一直提示0,我以为是要等几个小时,过了几天打开官方网站看了一下,有一个警告信息。

提供详细付款信息

只有在您提供此信息后 AdMob 才能投放您的广告

这是比较棘手的,需要信用卡,而且我上次搞谷歌支付用招商这种双币信用卡都不行,虽然可以用来买0.99美元的书,亏了我不少钱,后面还是不行,最后不得已去淘宝购买了礼品卡才搞定了,然后用来购买开发者账号

不过这次很幸运,成功了,ok,错误码从内部错误0 变成没有广告的错误码3了。

pulic static final int ERROR_CODE_INTERNAL_ERROR = 0;

  public static final int ERROR_CODE_INVALID_REQUEST = 1;

  public static final int ERROR_CODE_NETWORK_ERROR = 2;

  public static final int ERROR_CODE_NO_FILL = 3;


文章推荐
Google  如何创建销售广告,谷歌推广怎么添加广告系列
AppGalleryConnect服务支持Android、iOS、Web等平台,appgallery功能介绍
GMC账号被封后成功申诉案例解析,gmc解封方法
App Store注册美区(其他地区)ID最新教程!两步超简单!,iphone8 plus其他内存怎么清理


特别声明:以上文章内容仅代表作者本人观点,不代表ESG跨境电商观点或立场。如有关于作品内容、版权或其它问题请于作品发表后的30日内与ESG跨境电商联系。

搜索 放大镜
韩国平台交流群
加入
韩国平台交流群
扫码进群
欧洲多平台交流群
加入
欧洲多平台交流群
扫码进群
美国卖家交流群
加入
美国卖家交流群
扫码进群
ESG跨境专属福利分享群
加入
ESG跨境专属福利分享群
扫码进群
拉美电商交流群
加入
拉美电商交流群
扫码进群
亚马逊跨境增长交流群
加入
亚马逊跨境增长交流群
扫码进群
《开店大全-全球合集》
《开店大全-主流平台篇》
《开店大全-东南亚篇》
《CD平台自注册指南》
《开店大全-俄罗斯篇》
《韩国站内推广指南》
《韩国热销品预测》
《开店大全-日韩篇》
《开店大全-拉美篇》
《开店大全-欧洲篇》
通过ESG入驻平台,您将解锁
绿色通道,更高的入驻成功率
专业1v1客户经理服务
运营实操指导
运营提效资源福利
平台官方专属优惠
联系顾问

平台顾问

平台顾问 平台顾问

微信扫一扫
马上联系在线顾问

icon icon

小程序

微信小程序

ESG跨境小程序
手机入驻更便捷

icon icon

返回顶部

Baidu
map