Phonegap Desktop App external plugins

7.7k views Asked by At

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?

2

There are 2 answers

5
Miquel On BEST ANSWER

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.

0
Roope Hakulinen On

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.