cordova admobpro ads not showing on Android devices - javascript

I'm trying to put AdMob ads into my ionic android apps and to test the functionality I made an ionic app called AdMobTest. The plugin I'm using is the cordova-admob-pro plugin. Here is my AdMob code:
var admobid = {};
if (/(android)/i.test(navigator.userAgent)) { //Android
admobid = {
banner : 'ca-app-pub-2586564966169402/9782816366',
interstitial : 'ca-app-pub-2586564966169402/8345912938',
gotHereMsg1 : 'banner and interstitial have the android IDs'
};
} else if (/(ipod|iphone|ipad)/i.test(navigator.userAgent)) { //iOS
admobid = {
banner : 'Stand in iOS banner ID',
interstitial: 'stand in iOS interstitial ID',
gotHereMsg1 : 'banner and interstitial have the iOS IDs'
};
} else { //Neither
admobid = {
gotHereMsg1 : 'banner and interstitial have no IDs'
}
}
if (window.AdMob) {
var admob = window.AdMob;
admob.createBanner ({
adId : admobid.banner,
position : admob.AD_POSITION.BOTTOM_CENTER,
isTesting : false, //False for live ; True for production
autoShow : true
});
admob.prepareInterstitial ({
adId : admobid.interstitial,
autoShow : false
});
gotHereMsg2 = "window.AdMob is true";
} else {
gotHereMsg2 = "window.AdMob is not true";
}
//Got an ID and the actual ID's
document.getElementById("getIdCheck").innerHTML = admobid.gotHereMsg1;
document.getElementById("bannerId").innerHTML = admobid.banner;
document.getElementById("interstitialId").innerHTML = admobid.interstitial;
//window.AdMob is true and banner is created + interstitial is prepared
document.getElementById("isWindowAdmob").innerHTML = gotHereMsg2;
//Show interstitial function is executed or has not been executed
document.getElementById("startInterstitial").onclick = function () {
if (window.AdMob) {
var admob = window.AdMob;
admob.showInterstitial();
gotHereMsg3 = "Show Interstitial function has been executed";
} else {
gotHereMsg3 = "Show Interstitial function has not been executed";
}
document.getElementById("checkInterstitial").innerHTML = gotHereMsg3;
}
To show what works I kept in the tests I did using the "gotHereMsg" variables. All the variables get where I want them to go.
So gotHereMsg1 has the msg about android IDs and the IDs are also correct.
gotHereMsg2 returns "window.AdMob is true" which means the createBanner and prepareInterstitial function are being executed.
Lastly gotHereMsg3 returns "Show Interstitial function has been executed" when I click the button.
Even though all the functions are being executed and it obviously recognizes window.AdMob no banners are being shown. Hopefully this provides enough information to resolve this.
It might be worth noting that I am using ionicv1 and that the code is written in the ionic's app.js file under the $ionicPlatform.ready function.

I have plenty of experience with admob and ionic v1.
First, dont use cordova-admob-pro, they (he?) literally steals revenue from you! tuns of proof here
Use cordova-plugin-admob-free
if (window.admob !== undefined) {
admob.banner.config({
id: 'ca-app-pub-...',
autoShow: true
});
// Create banner
admob.banner.prepare();
// Show the banner
admob.banner.show();
admob.interstitial.config({
id: 'ca-app-pub-....',
autoShow: false
});
admob.interstitial.prepare();
}
Second I don't really see anything wrong...
I'd advise you to run the admob commands in the browser console windows while using remote inspect.....
and at same time watch the adb logcat to see if you get "NO FILL" or any other admob error

Related

Admob Javascript Need reward video listeners after completed video

Hi guys I need some help implementing reward video listeners.
I have a basic setup of admob nothing else other than using the plugin https://github.com/floatinghotpot/cordova-admob-pro.git
SO Simply better said I need to reward my players after watching the video how do I do it??
//this is my admob.js///////////////////////////////////////////////////////
var admobid = {};
if( /(android)/i.test(navigator.userAgent) ) {
admobid = { // for Android
banner: '',
interstitial: '',
rewardvideo: 'my code etc',
};
} else if(/(ipod|iphone|ipad)/i.test(navigator.userAgent)) {
admobid = { // for iOS
banner: '',
interstitial: '',
rewardvideo: 'my code etc',
};
} else {
admobid = { // for Windows Phone
banner: '',
interstitial: '',
};
}
if (AdMob) AdMob.createBanner( {
adId: admobid.banner,
isTesting: false,
overlap: true,
offsetTopBar: false,
position: AdMob.AD_POSITION.BOTTOM_CENTER,
bgColor: 'black'
});
if (AdMob) AdMob.prepareInterstitial( {adId:admobid.interstitial, autoShow:false} );
if (AdMob) AdMob.prepareRewardVideoAd({ adId:admobid.rewardvideo, autoShow:false} );
////////////////////////////////////////////////////////////////////////////////bellow is a simple function used in my game
///now with this I do my reward video call in a function in my game
///this bellow gets called when a button is hit and launches the reward
///video
freecoinsss:function()
{
if (AdMob) AdMob.showRewardVideoAd();
},
now my problem is how can I get the eventlistener with a function awarding my players for watching the video
"this is the function I want to call to award players" rewardforvideo();
coding in phaser btw
rewardforvideo:function()
{
var reward = 50;
var cash = localstorage.getItem('money');
var newcash = (reward+cash);
localstorage.setItem('money',newcash)
},
I found this https://developers.google.com/admob/android/rewarded-video-adapters
but Im stuck implementing it HElppppppp :(!!!!
ok, after much investigation, I have this working as from here:
if(AdMob) {
AdMob.showRewardVideoAd();
document.addEventListener('onAdPresent', function(data){
if(data.adType == 'rewardvideo') {
alert( data.rewardType ); // coins if you're using the test ID
alert( data.rewardAmount ); // 10 if you're using the test ID
}
});
}
I'm using the cordova-admob-pro plugin and using CLI to build for Android (at least for the moment)
I hope this helps someone.
I've been working on this issue for about an hour now, and due to the limited event listeners on the cordova-plugin-admobpro plugin, the best solution I was able to come up with was to set a timer for 10 seconds (the minimum ad length) and then wait for the onAdDismiss event to fire. Obviously this still means if a video is exited 10 seconds into a 30 second ad they would still receive credit.
See rough example below:
var canCredit;
//button event clicked to load/autodisplay ad
function showVideoAd(){
canCredit='no';
//start timer
setTimeout(function(){
canCredit='yes';
}, 10000); //10 seconds
AdMob.prepareRewardVideoAd({
adId: 'ca-app-pub-3839382062281896/9043804687',
autoShow: true,
});
}
function creditReward(){
//credit reward code here
}
//once ad is dismissed check if 10 seconds is up, if so, credit reward
$(document).on('onAdDismiss', function(e){
if(canCredit == 'yes')
creditReward();
});
With the code provided in the documentation (and your answer), you can click out of the ads instantly and still receive the reward.

Chrome doesn't close the notification

I'm currently using this implementation to use Browsers based Notifications :
https://developer.mozilla.org/en-US/docs/Web/API/Notification
This works like a charm.
if ("Notification" in window) {
if(Notification.permission === "granted") {
if($('#notify-on-message').is(':checked')) {
var notification = new Notification(username + ' : ' + data, {'icon': "/custom/favicon.gif"});
}
if ($('#notify-on-hl').is(':checked')) {
var patt = new RegExp("(^|\\W)"+selfusername+"(\\W|$)");
if(patt.test(data)) {
var notification = new Notification(username + ' highlighted you.', {'icon': "/custom/favicon.gif"});
}
}
}
}
The main issue I have is that on chrome based browsers, the notification just doesn't close itself after the 3 seconds delay.
It tried adding this after the var notification = ...
setTimeout(function() {
notification.close();
}, 2000);
Though that doesn't change a single thing. The notification remains.
Is it a known issue ? Is there an easy way to fix this behaviour I don't want ?
EDIT 1:
According to this page :
https://developer.mozilla.org/en-US/docs/WebAPI/Using_Web_Notifications
This is a known issue :
Note: Firefox and Safari close the notifications automatically after a few moments, e.g. 4 seconds.
This can also be done at the web application level using the Notification.close() method, for example with the following code:
var n = new Notification("Hi!");
n.onshow = function () {
setTimeout(n.close, 5000);
}
Though that code doesn't work. There is an error in the console that says that the notification doesn't have the close method or something like that.
Well actually I was wrong, the code
var message_notification = new Notification("Data");
setTimeout(function(){
message_notification.close();
}, 3000);
Works in both Firefox and Chrome. (And Safari too I guess)
Adding a tag to the option will close active popup before showing new once
var options = {
body: msg,
icon: "logo.png",
dir: "ltr",
tag: "group1"
};

How to open Twitter and Facebook app with Phonegap?

I am trying to have my PhoneGap application link to open a specific users profile page in the Twitter app. I know not everyone has the Twitter app installed on their device so I wanted to send them to the Play Store to download it if they didn't.
Problem is that every time I tap the link on my Android device I receive an error:
Application Error:
net::ERR_UNKNOWN_URL_SCHEME(twitter://user?screen_name=xerxesnoble)
My JavaScript is as follows:
//If Android
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
if (isAndroid) {
alert('Android!');
twitterCheck = function() {
alert('Android!');
var now = new Date().valueOf();
setTimeout(function () {
if (new Date().valueOf() - now > 100) return;
window.open('https://play.google.com/store/apps/details?id=com.twitter.android', '_system', 'location=no');
}, 50);
window.open('twitter://user?screen_name=XerxesNoble', '_system', 'location=no');
};
};
$('.twiterNav').click(function() {
window.open('twitter://user?screen_name=xerxesnoble', '_system', 'location=no');
});
Things that I've tried:
Using twitter:/// instead of twitter://
Adding <access origin="twitter://user?screen_name=xerxesnoble" /> to my config.xml
I'm not sure what else to try, nothing is working for Facebook either but right now I'm focusing on one issue at a time.
The Problem is that the InAppBrowser plugin was not installed. New versions of PhoneGap/Cordova do not come with all plugins installed- instead you choose what you want your App to have access to.
In terminal cd yourApp and $ cordova plugin add org.apache.cordova.inappbrowser
After doing that, it worked perfectly.
EDIT
Just to branch out a little bit more on how I got my .js to check if twitter was installed or not.
I installed another plugin : AppAvailability for iOS and Android
Then I altered my .js to look like this:
//Twitter checker
// If Mac//
var twitterCheck = function(){
appAvailability.check('twitter://', function(availability) {
// availability is either true or false
if(availability) { window.open('twitter://user?screen_name=xerxesnoble', '_system', 'location=no');}
else{window.open('https://itunes.apple.com/ca/app/twitter/id333903271?mt=8', '_system', 'location=no'); };
});
};
//If Android
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
if(isAndroid) {
twitterCheck = function(){
appAvailability.check('com.twitter.android', function(availability) {
// availability is either true or false
if(availability) {window.open('twitter://user?screen_name=xerxesnoble', '_system', 'location=no');}
else{window.open('https://play.google.com/store/apps/details?id=com.twitter.android', '_system', 'location=no');};
});
};
};
The documentation provided in the AppAvailability plugin was very helpful as well>
Hope that this helps someone!
Just a reference for others who might come here and want a bit more:
I've been able to get this working well (so far) on both iOS and Android, and dynamically falling back to the browser using the code below.
Required plugins are cordova-plugin-inappbrowser and cordova-plugin-appavailability
function openBrowser (url) {
if (!url) {
return;
}
// turn my url into a scheme/intent url
getAvailabilityScheme(url, function (url) {
window.open(url, '_system');
});
}
function getAvailabilityScheme (url, callback) {
var schemeOrPackage;
var schemeUrl;
// check for appavaialbility plugin
if (!window.appAvailability) {
callback(url);
}
// facebook
if (url.indexOf('facebook.com/') !== -1) {
schemeOrPackage = isAndroid ? 'com.facebook.katana' : 'fb://'
schemeUrl = 'fb://profile/' + url.split('facebook.com/')[1];
}
// twitter
if (url.indexOf('twitter.com/') !== -1) {
schemeOrPackage = isAndroid ? null : 'twitter://'
schemeUrl = 'twitter://user?screen_name=' + url.split('twitter.com/')[1];
}
if (schemeOrPackage && schemeUrl) {
window.appAvailability.check(schemeOrPackage, function () {
callback(schemeUrl);
}, function () {
callback(url);
});
} else {
callback(url);
}
}
Using it is easy, just call the openBrowser(url) method with a normal website url. The only issue i found was that for a facebook page, it needs to an ID not the slug name

Titanium Facebook module not completing login on iOS 7

I've run into a weird issue using Titanium 3.2.0.GA and the Facebook module. When I try calling fb.authorize(); and if I'm logged into Facebook through iOS 7, the dialog pops up asking if I would like to allow it to blah blah blah. But once I tap "Allow", it triggers the login event with code -1, and is unsuccessful. However, if I'm not logged into Facebook through iOS 7, and login to Facebook through Safari after calling fb.authorize();, everything works as expected and the login event is triggered successfully.
var fb = require('facebook');
fb.appid = ****;
fb.permissions = ['email'];
fb.forceDialogAuth = false;
fb.addEventListener("login", function(e) {
if (fb.success && fb.accessToken != null) {
console.log(fb.accessToken);
}
});
And like I said above, when the Facebook button is pressed I just call fb.authorize();.
Is anyone else having issues like this on iOS 7 using Titanium?
Looks like I fixed it. On my Facebook app, I had to add an iOS app and turn the "Single Sign On" on. Facebook was having issues last night and wouldn't let me make changes to my app but I just tried it today and it works now. I think this might be something new for iOS 7, but I'm not sure. However, turning Single Sign On to On worked for me.
Just declare All bellow variables in calling function only not globally other wise each time it will call fb.authorize().
i.e
var fb = null;
function facbooksharing(sharingData){
if(fb == null){
fb = require('facebook');
fb.appid = "******";
fb.permissions = ['publish_stream', 'read_stream','publish_actions'];
fb.forceDialogAuth = true; `enter code here`
}
if(fb.loggedIn==true)
{
fb.dialog("feed", sharingData, showRequestResult);
}else{
fb.authorize();
}
function showRequestResult(e)
{
if (e.success)
{
if (e.result)
{
Ti.API.info("Data Shared between your friend successfully.");
}
}
}
fb.addEventListener("login", function(e) {
if (fb.success && fb.accessToken != null) {
console.log(fb.accessToken);
}
});
}
Let me know is this resolve your problem or not.

Chrome Extension notification only shows-up once?

This verifies whether the page is https and whether a localStorage item evaluates to true or false, and displays a notification based on that. The code is placed in the popup.js:
chrome.tabs.query({
active: true,
lastFocusedWindow: true
}, function(array_of_Tabs) {
var tab = array_of_Tabs[0];
var url = tab.url;
if (url.indexOf('https:') === 0 && localStorage.getItem("secureRead").value !== true) {
chrome.extension.getBackgroundPage().showNotify();
}
});
The actual notification code is placed in the background.js file:
var notification = webkitNotifications.createNotification(
'icon48.png',
'Secure page detected.',
'Checking "Enable HTTPS reading" in the setting is required.'
);
function showNotify()
{
notification.show();
}
The problem is that this only works once, globally. No other page is then detected, evaluated and no notification is shown. What am I doing wrong?
There are no errors thrown at me either.
First, you should be aware that the current notification system (i.e. webkitNotifications.createNotification) is deprecated, and has been removed from Chrome, at least on Windows and ChromeOS. See http://developer.chrome.com/extensions/desktop_notifications.html for details.
Second, the notification might be null if it's closed by the user; I'd try this:
function showNotify()
{
if (notification == null)
{
notification = webkitNotifications.createNotification(
'icon48.png',
'Secure page detected.',
'Checking "Enable HTTPS reading" in the setting is required.'
);
}
notification.show();
}

Categories