(just remember to include your own jQuery / Zepto)
Last active
August 29, 2015 14:14
-
-
Save stefek99/4aba7338b4059ea35ac1 to your computer and use it in GitHub Desktop.
The code accompanying blog post located at: http://www.iamthespecialist.com/2015/02/android-phonegap-cordova-plugin-admob.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" ?> | |
<widget xmlns = "http://www.w3.org/ns/widgets" | |
xmlns:gap = "http://phonegap.com/ns/1.0" | |
id = "net.stefanow.admobtest" | |
versionCode = "10" | |
version = "1.0.0" > | |
<!-- versionCode is optional and Android only --> | |
<name>AdMob test</name> | |
<description>Lorem Ipsum.</description> | |
<author href="https://michalstefanow.com" email="[email protected]"></author> | |
<!-- http://docs.build.phonegap.com/en_US/2.9.0/configuring_features.md.html --> | |
<preference name="permissions" value="none"/> | |
<gap:plugin name="com.google.cordova.admob" source="plugins.cordova.io" /> | |
<gap:plugin name="net.tunts.webintent" version="0.2.1" /> | |
</widget> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width" /> | |
<title>Android - Phonegap - Cordova - Plugin - AdMob - Intents</title> | |
<script type="text/javascript" src="jquery.min.js"></script> | |
<script type="text/javascript" src="cordova.js"></script> | |
<script type="text/javascript" src="main.js"></script> | |
</head> | |
<body> | |
<button id="showInterstitial">Show interstitial</button> <br> | |
<button id="intent-tel">Dial a number</button> <br> | |
<button id="intent-settings">Open settings</button> <br> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener("deviceready", function() { | |
if(typeof AdMob !== "undefined") { | |
AdMob.createBanner({ | |
adId: "ca-app-pub-6189485697172341/8276412804", | |
position : AdMob.AD_POSITION.BOTTOM_CENTER, | |
autoShow : true | |
}); | |
} else { | |
alert("AdMob is not defined --> (something is not right)"); | |
} | |
$("#showInterstitial").on("click", function() { | |
if(typeof AdMob !== "undefined") { | |
AdMob.prepareInterstitial({ | |
adId:"ca-app-pub-1299448460150394/4060197860", | |
autoShow: true | |
}); | |
} else { | |
alert("AdMob is not defined --> (something is not right)"); | |
} | |
}); | |
}); | |
$(function() { | |
var isAndroid = function() { | |
return /(android)/i.test(navigator.userAgent); | |
}; | |
var successCallback = function() { | |
alert("returned to the app from the intent"); | |
}; | |
var errorCallback = function(error) { | |
var err_string = JSON.stringify(err, null, 2); | |
alert(err_string); | |
}; | |
$("#intent-tel").on("click", function() { | |
if (isAndroid() === false) { | |
alert("Not Android device, intents are not likely to work"); | |
return false; | |
} | |
window.plugins.webintent.startActivity({ | |
action: window.plugins.webintent.ACTION_VIEW, | |
url: 'tel: 00447586294279' | |
}, successCallback, errorCallback); | |
}); | |
$("#intent-settings").on("click", function() { | |
if (isAndroid() === false) { | |
alert("Not Android device, intents are not likely to work"); | |
return false; | |
} | |
window.plugins.webintent.startActivity({ | |
action: "android.settings.LOCATION_SOURCE_SETTINGS" | |
}, successCallback, errorCallback); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment