Phonegap Desktop App external plugins
Asked Answered
R

2

6

Has anyone had luck adding external plugins to the Phonegap Desktop App? I have had success adding core plugins like "Device" but not external ones. I am trying to add com.admob.google to my project and I can not get admob to be recognized as a command. In the config.xml I add:

<gap:plugin name="com.admob.google" source="plugins.cordova.io" />

And in my deviceReady function in my .js file I have:

try{
    admob.requestInterstitialAd(); //or any other admob command
}
catch(err){
    alert("admob not loaded");
}

Every time on my device (via Phonegap Developer App) I get the alert saying that "admob not loaded".

Am I mixing Phonegap and Phonegap Build commands?

Does the Phonegap Build Desktop App not support auto-inclusion of external plugins yet?

Rothstein answered 22/12, 2014 at 15:4 Comment(1)
The inclusion of plugins via config.xml only works for PGBuild.Persia
E
6

I'm the author of the plugin you are trying to use. It seems you are using the command line interface which it doesn't have any automatization on <gap:plugin ...> yet (and I'm not sure that it's comming in the near future).

As Sanfor says, if you are using Phonegap CLI, you should add every plugin manually:

phonegap local plugin add cordova-admob

Or if you are using Cordova:

cordova plugin add cordova-admob

If you are using Phonegap Build, you should put the tag in config.xml:

<gap:plugin name="cordova-admob" source="npm" />

In that case, you can also follow the instructions at https://github.com/appfeel/admob-phonegap-build-demo.git to test the demo app in your Phonegap Build account.

Remember to always use admob after deviceready event has been fired:

function onAdLoaded(e) {
  if (e.adType === admob.AD_TYPE.INTERSTITIAL) {
    admob.showInterstitialAd();
  }
}

function onDeviceReady() {
  document.removeEventListener('deviceready', onDeviceReady, false);

  // Set AdMobAds options:
  admob.setOptions({
    publisherId:          "YOUR_PUBLISHER_ID",                  // Required
    interstitialAdId:     "YOUR_PUBLISHER_OR_INTERSTITIAL_ID",  // Optional
  });

  // Start showing banners inmediately:
  admob.createBannerView();

  // To show an interstitial, call admob.showInterstitialAd() when onAdLoaded is fired:
  document.addEventListener(admob.events.onAdLoaded, onAdLoaded, false);
  admob.requestInterstitial();

  // You could also request and show an interstitial like this:
  // admob.requestInterstitialAd({ autoShowInterstitial: true});
}

document.addEventListener('deviceready', onDeviceReady, false);

It's interesting to know if you are testing with CLI to later use PGB. However, I'm not sure if it helps a mock-up of the admob functionality. Let me know if it's your case. The only situation that comes to my mind is that you would like to test the app in a desktop browser, where plugins aren't supported. But even in that case I would suggest you to use ripple incubator from github (or even weinre, but if you are in a mac it's better to use safari developer tools).

EDIT 2016-04-22

Updated old plugin references to newest ones and npm source for phonegap build.

Earthaearthborn answered 22/12, 2014 at 22:59 Comment(5)
I was using the "Phonegap Desktop App" (phonegap.com/blog/2014/12/11/phonegap-desktop-app-beta) which I have come to find out is the GUI version of the CLI and does not support external plugins at this time. I ended up using my tried and true method of building with Phonegap Build and setting in your plugin via the config.xml and managed to get it to work. Great plugin by the way, very easy to use and tons of features/methods.Rothstein
facing this issue, can you help us solve it? #36775678Greff
sorry, it is not related, that's why I asked if you can help us as i thought you might be able to.Greff
@Greff oh! sorry, I was taking a look to the question to see but I'm using mac and also it's been long time that I haven't been using phonegap desktop, normally what I do is I use phonegap serve (in cli) while developing and debugging in browser. phonegap serve is a good option even when it has'nt all access to native plugins (it emulates their behavior). When there is a rc I build the app and test in real device. This is my experience :)Earthaearthborn
thanks Miquel, m too shifted to cli, and it didn't caused any issueGreff
V
1

I'm not an expert, but I haven't got that to work. I think you are indeed mixing PG and PGB configurations (gap:plugin). Since I haven't had luck with getting those work (I suppose you would need to add those via CLI), I can only suggest what I've done: mock those plugins that doesn't exist by default. You can for example define admob object with the necessary functions available for you.

Vinegarroon answered 22/12, 2014 at 15:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.