问题
I'm trying to display interstitial Ad in my PhoneGap app but it's not working; it's not displaying the ad at all. I followed the instructions here.
Apart from trying to make it work, what I also need to do is to show the interstitial at a particular time (probably when the game is over) but I dont know how to refer to the Java code from JavaScript code to show the loaded interstitial ad.
Please help.
回答1:
I recently got AdMob working within my Cordova 4 project after much fiddling. Forget the instructions you linked to in your question, which are not for cordova/phonegap builds.
Step 1: You will need to install the Cordova/Phonegap plugin for Admob. (This assumes you have already created the project files.) In my case, e.g. for Cordova command line interface, I used Terminal, cd
to my project's root directory and then type:
cordova plugin add com.admob.google
For your Phonegap setup, you will likely need to do one of the following:
Add this to your project's config.xml file.
<gap:plugin name="com.admob.google" source="plugins.cordova.io" />
OR (for Phonegap CLI), type this command into Terminal from your project's root directory,
phonegap local plugin add com.admob.google
Once you have the plugin, you can use javascript to control Admob behavior.
Step 2: Add appropriate javascript for Admob plugin to your project, linked in your index.html file. I ran into some trouble here, so just to prove to myself that the plugin really works, I removed (backed up) everything from my project's WWW folder and added the exact files from the WWW folder from this project and later this one on Github. Both work. It was then a matter of making smarter-people-than-myself's javascript work in my app.
A few tips
- Don't use the emulator. Admob may not perform correctly in the emulator.
- For some reason, I am not served Admob ads over LTE/4G. If you are certain you have done everthing correctly, try connecting your device to WIFI when testing
- If your app is still not working, and you don't know what elese to do, try to validate your HTML. Invalid html will affect performance of javascript.
- Make sure you have added
<script type="text/javascript" src="cordova.js"></script>
in your head of your index file.
来源:https://stackoverflow.com/questions/27686998/interstatial-admob-using-phonegap-not-working