我制作了一个包含Admob广告的应用程序。我做了教程中的所有事情,一切都很好,直到我把自己的Ad id它没有显示出来。但是当我从互联网或教程中将Ad id更改为任何广告id时,它可以正常工作。我不知道问题到底出在哪里…它是来自代码还是来自我的admob。
这是代码:
public class main extends Activity {
WebView web1;
private AdView mAdView;
InterstitialAd mInterstitialAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
//full screen ads
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-4400857573550757/5605673426");
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
requestNewInterstitial();
}
});
requestNewInterstitial();
//---------------- START ORDERING BANNER ADD ------------
// Initialize the Mobile Ads SDK.
MobileAds.initialize(this, "ca-app-pub-4400857573550757/2713039825");
mAdView = (AdView) findViewById(R.id.ad_view);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
// System.out.println(adRequest.isTestDevice(this))
//---------------------------------------------------
// mInterstitialAd.show();
this.setRequestedOrientation(
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
final Handler handler = new Handler();
Timer timer = new Timer();
TimerTask doAsynchronousTask = new TimerTask() {
@Override
public void run() {
handler.post(new Runnable() {
public void run() {
try {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
// beginPlayingGame();
}
} catch (Exception e) {
}
}
});
}
};
timer.schedule(doAsynchronousTask, 0, 60000); //execute in every 10 ms
web1 = (WebView) findViewById(R.id.webview);
WebSettings webSettings = web1.getSettings();
webSettings.setJavaScriptEnabled(true);
web1.setWebViewClient(new WebViewClient());
web1.loadUrl("MYWEBSITE");
web1.setWebViewClient(new NoErrorWebViewClient());
}
private void requestNewInterstitial() {
AdRequest adRequest = new AdRequest.Builder().build();
// .addTestDevice("SEE_YOUR_LOGCAT_TO_GET_YOUR_DEVICE_ID")
mInterstitialAd.loadAd(adRequest);
}}
这是布局代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:paddingBottom="1dp"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:paddingTop="1dp"
tools:context=".main">
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<com.google.android.gms.ads.AdView
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="ca-app-pub-4400857573550757/2713039825" /></RelativeLayout>
我在这里上传了日志:日志
09-03 08:14:53.186 2726-2726/muteb.speak I/Ads: Starting ad request.
09-03 08:14:53.190 2726-2726/muteb.speak I/Ads: Use AdRequest.Builder.addTestDevice("19AA808AE9FC61F7FA6E4AA2B99F2557") to get test ads on this device.
09-03 08:14:53.258 2726-2726/muteb.speak W/GooglePlayServicesUtil: Google Play services is missing.
09-03 08:14:53.262 2726-2726/muteb.speak W/GooglePlayServicesUtil: Google Play services is missing.
09-03 08:14:53.270 2726-2726/muteb.speak I/Ads: Starting ad request.
09-03 08:14:53.274 2726-2726/muteb.speak I/Ads: Use AdRequest.Builder.addTestDevice("19AA808AE9FC61F7FA6E4AA2B99F2557") to get test ads on this device.
请参阅上述日志…您正在测试的设备需要使用Google Play服务库进行更新,请参阅此链接Android Studio with Google Play:缺少Google Play服务
显然,如果启用JavaScriptwebSettings. setJavaScriptEn的(真);
来自AdMob的横幅将不起作用(至少在我的情况下)。
我找不到解决这种情况的方法,但我非常期待听到其他人的想法。