当前位置: 首页> 财经> 股票 > admob 广告分析

admob 广告分析

时间:2025/7/12 7:01:38来源:https://blog.csdn.net/u013170888/article/details/141369593 浏览次数:0次

1、测试广告集成,官方文档 https://developers.google.com/admob/android/quick-start?hl=zh-cn

dependencies {implementation("com.google.android.gms:play-services-ads:23.3.0")
}

2、广告集成,集成测试激励广告。

public class MainActivity extends AppCompatActivity {String TAG = "admob";private RewardedAd rewardedAd;Context context;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);EdgeToEdge.enable(this);setContentView(R.layout.activity_main);context = this;new Thread(() -> {// Initialize the Google Mobile Ads SDK on a background thread.MobileAds.initialize(this, initializationStatus -> {});}).start();Button button = findViewById(R.id.button);button.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {AdRequest adRequest = new AdRequest.Builder().build();RewardedAd.load(context, "ca-app-pub-3940256099942544/5224354917",adRequest, new RewardedAdLoadCallback() {@Overridepublic void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {// Handle the error.Log.d(TAG, loadAdError.toString());rewardedAd = null;}@Overridepublic void onAdLoaded(@NonNull RewardedAd ad) {rewardedAd = ad;Log.d(TAG, "Ad was loaded.");if (rewardedAd != null) {Activity activityContext = MainActivity.this;rewardedAd.show(activityContext, new OnUserEarnedRewardListener() {@Overridepublic void onUserEarnedReward(@NonNull RewardItem rewardItem) {// Handle the reward.Log.d(TAG, "The user earned the reward.");int rewardAmount = rewardItem.getAmount();String rewardType = rewardItem.getType();}});} else {Log.d(TAG, "The rewarded ad wasn't ready yet.");}rewardedAd.setFullScreenContentCallback(new FullScreenContentCallback() {@Overridepublic void onAdClicked() {// Called when a click is recorded for an ad.Log.d(TAG, "Ad was clicked.");}@Overridepublic void onAdDismissedFullScreenContent() {// Called when ad is dismissed.// Set the ad reference to null so you don't show the ad a second time.Log.d(TAG, "Ad dismissed fullscreen content.");rewardedAd = null;}@Overridepublic void onAdFailedToShowFullScreenContent(AdError adError) {// Called when ad fails to show.Log.e(TAG, "Ad failed to show fullscreen content.");rewardedAd = null;}@Overridepublic void onAdImpression() {// Called when an impression is recorded for an ad.Log.d(TAG, "Ad recorded an impression.");}@Overridepublic void onAdShowedFullScreenContent() {// Called when ad is shown.Log.d(TAG, "Ad showed fullscreen content.");}});}});}});}
}

3、查看广告activity

adb shell dumpsys avtivity topTASK 10266:com.mycode.admobdemo id=73 userId=0ACTIVITY com.mycode.admobdemo/com.google.android.gms.ads.AdActivity 90fc91c pid=13407
...View Hierarchy:DecorView@a5b4167[AdActivity]android.widget.LinearLayout{df84975 V.E...... ........ 0,0-1080,2088}android.view.ViewStub{d73fddf G.E...... ......I. 0,0-0,0 #10201b3 android:id/action_mode_bar_stub}android.widget.FrameLayout{66808ac V.E...... ........ 0,0-1080,2088 #1020002 android:id/content}com.google.android.gms.ads.internal.overlay.h{fc4f65f V.E...... ........ 0,0-1080,2088 #3e8}com.google.android.gms.ads.internal.webview.ab{88e3228 V.E...... ........ 0,0-1080,2088}com.google.android.gms.ads.internal.video.s{b373a2c V.E...... ........ 0,0-1080,2088}android.widget.FrameLayout{4455cf5 V.E...... ........ 0,594-1080,1204}com.google.android.gms.ads.internal.video.exoplayer.n{e596a8a V.ED..... ........ 0,1-1080,608}com.google.android.gms.ads.internal.webview.ai{b4498fb VFEDHVC.. .F...... 0,0-1080,2088 aid=2}android.widget.TextView{ff3cd18 V.ED..... ........ 465,0-614,56}com.google.android.gms.ads.internal.overlay.r{bdbd371 VFE...C.. ........ 0,0-0,0}android.widget.ImageButton{16ba556 GFED..C.. ......I. 0,0-0,0}android.view.View{e971d0a V.ED..... ........ 0,2088-1080,2220 #1020030 android:id/navigationBarBackground}

4、Layout Inspector查看布局
在这里插入图片描述

关键字:admob 广告分析

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: