即时通讯尝试将广告添加到我的android phonegap应用程序但我没有得到任何...我使用phonegap 0.3.3
我的admob关键广告键如下:ca-app-pub-9718633180389415/1973821888
我的config.xml我有:
<plugin name="com.admob.google" spec="4.0.8" source="pgb" />
然后尝试我的索引:
function onDeviceReady() {
document.removeEventListener('deviceready', onDeviceReady, false);
// Set AdMobAds options:
admob.setOptions({
publisherId: "ca-app-pub-9718633180389415/1973821888", // Required
interstitialAdId: "ca-app-pub-9718633180389415/1973821888", // Optional
tappxIdiOs: "/XXXXXXXXX/Pub-XXXX-iOS-IIII", // Optional
tappxIdAndroid: "/XXXXXXXXX/Pub-XXXX-Android-AAAA", // Optional
tappxShare: 0.5 // Optional
});
// Start showing banners (atomatic when autoShowBanner is set to true)
admob.createBannerView();
// Request interstitial (will present automatically when autoShowInterstitial is set to true)
admob.requestInterstitial();
}
但会显示注意事项: 我正在使用https://github.com/sunnycupertino/cordova-plugin-admob-simple
答案 0 :(得分:3)
此处cordova-admob
插件的作者。你试过isTesting: true
了吗?你在真正的设备上运行吗?请注意,它不适用于浏览器(仅限模拟器或真实设备)。
在config.xml
:
<gap:plugin name="phonegap-admob" source="npm"/>
在你的javascript中:
function onDeviceReady() {
document.removeEventListener('deviceready', onDeviceReady, false);
// Set AdMobAds options:
admob.setOptions({
publisherId: "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB", // Required
interstitialAdId: "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII", // Optional
isTesting: true // Optional
});
// Start showing banners (atomatic when autoShowBanner is set to true)
admob.createBannerView();
// Request interstitial (will present automatically when autoShowInterstitial is set to true)
admob.requestInterstitialAd();
}
document.addEventListener("deviceready", onDeviceReady, false);
在此处查看更多详情:https://github.com/appfeel/admob-google-cordova/wiki/Setup
答案 1 :(得分:0)
不确定这是否有用,但我认为我使用的是同一个插件,事实上,我正在使用这个插件:
https://github.com/admob-google/admob-cordova
要使用该插件,我编写了以下代码:
var AdmobManager = {
// admob configuration
admobCfg: {},
// Initialize admob support, and start showing a banner right away
initAdmob: function () {
// If we don't have admob support, don't try to configure anything
if (!admob)
return;
// Configure the IDs for the iOS and Android banner and interstitial ads
AdmobManager.admobCfg.iosCfg = {
banner: "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB",
interstitial: "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII"
};
AdmobManager.admobCfg.androidCfg = {
banner: "ca-app-pub-XXXXXXXXXXXXXXXX/RRRRRRRRRR",
interstitial: "ca-app-pub-XXXXXXXXXXXXXXXX/HHHHHHHHHH"
};
// Choose ad IDs based on platform
AdmobManager.admobCfg.activeCfg = (/(android)/i.test(navigator.userAgent)) ? AdmobManager.admobCfg.androidCfg : AdmobManager.admobCfg.iosCfg;
// Now we can init admob: set the IDs, and build a param for testing mode
admob.initAdmob(AdmobManager.admobCfg.activeCfg.banner, AdmobManager.admobCfg.activeCfg.interstitial);
AdmobManager.admobCfg.extraParams = new admob.Params();
AdmobManager.admobCfg.extraParams.isTesting = true;
// Request banner ads immediately upon app start
admob.showBanner(admob.BannerSize.BANNER, admob.Position.BOTTOM_CENTER, AdmobManager.admobCfg.extraParams);
},
// start allowing Admob interstitials
enableAdmobInterstitial: function () {
// If we don't have admob support, don't try to configure anything
if (!admob)
return;
// Set up a listener for showing an interstitial once it arrives
document.addEventListener(admob.Event.onInterstitialReceive, function (message) {
admob.showInterstitial();
}, false);
// Request an interstitial to be sent
admob.cacheInterstitial(AdmobManager.admobCfg.extraParams);
}
}
在我显示登录屏幕之前,我致电AdmobManager.initAdmob()
,然后在登录后,我致电AdmobManager.enableAdmobInterstitial()
。
当然,一旦您完成测试,您就会想要将isTesting
更改为false。