Android - Phonegap - Cordova - Plugin - AdMob - Intents
(just remember to include your own jQuery / Zepto)
(just remember to include your own jQuery / Zepto)
<?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="mstefanow@gmail.com"></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> |
<!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> |
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); | |
}); | |
}); |