AdMob Integration with Android
I'm trying to get Admob integrated into my Android app and am having trouble. Using a combination of other posts I've gotten this far:
var adUrl = "http://tothsolutions.com/ad/mobile";
var numRetries = 0;
var maxRetries = 10;
ajaxCall(adUrl, displayAd);//this just does a httpclient get request and calls displayad onload
function displayAd() {
numRetries++;
var html = addEventToHtml(this.responseText);
if (html && html.indexOf("No ads found") == -1) {
var adWebView = Ti.UI.createWebView({ /*url: adUrl,*/height: 48, bottom: 0, left: 0, right: 0,
scalesPageToFit: false, touchEnabled: false, html: html
});
win.add(adWebView);
}
}
Titanium.App.addEventListener("openWebView", function (e) {
console.log("in adwebview click event");
console.log(e.url);
Titanium.Platform.openURL(e.url);
});
function addEventToHtml(html){
var regex = /href=".*">/;
var links = [];
try {
links = html.match(regex);
console.log('number of links found: ' + links.length);
}
catch (exc){
console.log('no links found');
if (numRetries <= maxRetries) {
setTimeout(displayAd, 10000);
}
//console.log(html);
return html ? html.replace("</body>", "No ads found!</body>") : null;
}
links[0] = links[0].substring(6, links[0].length - 2);
Ti.API.info('link: ' + links[0]);
var newLink = "href=\"#\" onClick=\"Ti.App.fireEvent('openWebView', {url:'" + links[0] + "'});return false\">";
var newHtml = html_code.replace(regex, newLink);
return newHtml;
}
The code seems like it should work. The problem is that every time it does a GET on my external web page containing admob code, it only generates a 1x1 pixel image instead of a link so the code above generates "no links found". Is admob blocking this approach now and if so, how am I supposed to get ads working?