如何解决更新/迁移 - Admob 播放服务 Ads 19.8.0
我已从 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();
}
}
有人知道怎么解决这个问题吗?
我有点失落了嘿嘿
谢谢你,对不起我的英语
解决方法
新的 Interstitial API 不再支持这些方法。要使用 com.google.android.gms.ads.interstitial.InterstitialAd
,请参阅 Interstitial 的更新集成指南:https://developers.google.com/admob/android/interstitial-fullscreen。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。