【发布时间】:2021-03-26 22:07:18
【问题描述】:
我已从 Admob 更新到新版本的 com.google.android.gms: play-services-ads: 19.8.0,但我无法让它工作。
我已阅读从 19.7.0 版的 google play 服务广告迁移。 https://developers.google.com/admob/android/migration 我以不同的方式尝试了我的代码,但它不起作用。
其中一个错误是:'com.google.android.gms.ads.InterstitialAd' 已弃用 → 我已通过导入 com.google.android.gms.ads.interstitial.InterstitialAd 解决了它;
导入后 .... InterstitialAd 我得到了不同的错误,例如:
无法解析“InterstitialAd”中的方法“setAdUnitId”
无法解析“InterstitialAd”中的方法“loadAd”
无法解析“InterstitialAd”中的方法“isLoaded”
我的代码示例:(适用于旧版本)
package com.ejemplo.mejorar;
import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.LinearLayout;
import com.google.android.gms.ads.interstitial.InterstitialAd;
//import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
public class MainActivity extends Activity {
//Variables code admob Ads & interstitial//
private InterstitialAd interstitialAd = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(com.ejemplo.mejorar.R.layout.activity_main);
//Interstitial -------------
AdRequest adrequest_interstitial = new AdRequest.Builder().build();
interstitialAd = new InterstitialAd(this);
interstitialAd.setAdUnitId("CODEADMOB");
interstitialAd.loadAd(adrequest_interstitial);
}
//Inicio paginas----------------------------------------------------
public void page1(View view)
{
Intent i = new Intent (this, PaginaConf.class);
startActivity(i);
int randomAd = (int)(Math.random()*10);
if(interstitialAd!=null && randomAd<=1)
{
if(interstitialAd.isLoaded()){ interstitialAd.show(); }
}
}
//---------------------------------------------
public void close(View view)
{
finish();
}
}
有谁知道如何解决这个问题?
我有点失落嘿嘿
谢谢你,对不起我的英语
【问题讨论】:
标签: android android-studio admob google-play-services