7

Using phonegap 3.1 I'm trying to hide the splash screen when device is ready:

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

function onDeviceReady() {
 navigator.splashscreen.hide();
}

But it returns:

Cannot call method 'hide' of undefined

The navigator object doesn't including the splashscreen attribute.

I've tried it on phonegap 2.9 and it works fine.

griffon vulture
  • 6,594
  • 6
  • 36
  • 57

6 Answers6

10

After research and experiments this is what we had to do in order to get it work:

cordova plugin add org.apache.cordova.splashscreen

cordova build

Then, cordova build was adding the wrong lines to the config.xml - So we had to change it to the following:

 <feature name="SplashScreen">
        <param name="android-package" value="org.apache.cordova.splashscreen.SplashScreen" />
 </feature>

And in your main activity

 super.setIntegerProperty("splashscreen", R.drawable.splash);
 super.setIntegerProperty("splashScreenDelay", 10000); //time to display the splash

Finally we have been able to use hide method from javascript.

griffon vulture
  • 6,594
  • 6
  • 36
  • 57
3

Are you using the CLI to add the SplashScreen plugin? You have to add the plugin with $ cordova plugin add org.apache.cordova.splashscreen (copy the plugin code from plugins.cordova.io into /yourApp/plugins/org.apache.cordova.splashscreen/ and then later cordova build to copy the plugin code into the appropriate platform location.

MBillau
  • 5,366
  • 2
  • 28
  • 29
1

If you're using phonegap build, rather than doing

cordova plugin add ...

from the command line, you'll need to add the plugin and feature to the config.xml:

<gap:plugin name="org.apache.cordova.splashscreen" />
<feature name="SplashScreen">
    <param name="android-package" value="org.apache.cordova.splashscreen.SplashScreen" />
    <param name="ios-package" value="CDVSplashScreen" />
</feature>
MrPotes
  • 356
  • 2
  • 10
0

Only thing I can guess is to double check that you have <script type="text/javascript" charset="utf-8" src="cordova.js"></script> in the head of your HTML that is calling that JS. Sorry, haven't messed with 3.1 yet.

Dom
  • 2,569
  • 1
  • 18
  • 28
0

Add this:

<preference name="SplashScreen" value="splash.png" />
<preference name="SplashScreenDelay" value="3000" />

The navigator.splashscreen.hide() doesn't work for me either.

UPDATE: navigator.splashscreen.hide() only works when building online (phonegap build).

bkomac
  • 1,140
  • 10
  • 9
  • When stuff only works when building with PGB, it means you have missing plugins on your side. Install the splash screen plugin with `cordova plugin add org.apache.cordova.splashscreen` and it should work correctly on your Cordova CLI. – andreszs Feb 05 '15 at 04:17
0

After upgrading to Phonegap Desktop 0.3.6, I had a similar issue and one of my older apps was stuck on the splash screen. In the configuration window, it was showing the correct app name and version and it was updating as soon as I was modifying the config.xml. In the console I had only one error: 500 for http://localhost:3000/cordova_plugins.js

A new app was working fine.

I tried all the above:

  • splash screen plugin and configuration
  • adding the cordova.js and cordova_plugins.js to index.html. This is not necessary anymore since many versions ago - the build does it for you.
  • in the platforms/android/assets/www folder there were cordova.js and cordova_plugins.jsfiles present
  • in the config.xml there was specified <content src="index.html" />

In the end what solved my problem was to completely delete the platforms folder and run cordova platform add android again. I guess it's safe to do this after each Phonegap upgrade.

Adrian Ber
  • 20,474
  • 12
  • 67
  • 117