在应用程序的第一次执行期间不显示 Admob.2 [英] Admob is not displayed during the app's first execution. 2
本文介绍了在应用程序的第一次执行期间不显示 Admob.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I made an Android app with Phonegap (Cordova 2.5.0). And I put admob in my app using this plugin. ( https://github.com/sainttex/PhoneGap-Android-Native-AdMob )
Admob is displayed in my app. But there's a problem. During the first execution, admob's not showing up. After closing the app and re-starting it, admob is displayed. From the second execution onwards, admob is displayed.
If I don't use the app for a while (about one hour), then run the app, the problem comes up again.
What can I do to fix problem?
Bellow is my code.
[MainActivity.java code]
package com.***.*******;
import com.google.ads.*;
import org.apache.cordova.DroidGap;
import android.os.Bundle;
import android.widget.LinearLayout;
//import android.view.Menu;
public class MainActivity extends DroidGap {
private static final String AdMob_Ad_Unit = "*************";
private AdView adView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
adView = new AdView(this, AdSize.BANNER, AdMob_Ad_Unit);
LinearLayout layout = super.root;
layout.addView(adView);
AdRequest request = new AdRequest();
adView.loadAd(request);
super.loadUrl("file:///android_asset/www/index.html");
}
}
[AndroidManifest.xml code]
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
解决方案
Install cordova admob plugin.
cordova plugin add com.admob.AdmobPlugin
Then add this code.
function onDeviceReady() {
admobAd.initBanner("ca-app-pub-1738093038576474/9839543541",admobAd.AD_SIZE.BANNER.width,admobAd.AD_SIZE.BANNER.height);//ios Interstitial
admobAd.showBanner(admobAd.AD_POSITION.BOTTOM_CENTER);
}
document.addEventListener('deviceready',onDeviceReady, false);
这篇关于在应用程序的第一次执行期间不显示 Admob.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文