Search code examples
javascriptionic-frameworkphonegap

JavaScript PhoneGap


I have created a Cordova PhoneGap app using CLI for and added Android platform. I have tried to add a splash screen using Cordova splash screen plugin as indicated in this link.

When I run the app on Android using PhoneGap app and PhoneGap desktop, it doesn't show the splash screen.The following is the config.xml located at the top level in root project folder:

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.splash.app" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <preference name="SplashSreen" value="screen" />
  <preference name="SplashSreenDelay" value="1000" />

  <author email="dev@cordova.apache.org" href="http://cordova.io">
    Apache Cordova Team
  </author>
  <content src="index.html" />
  <plugin name="cordova-plugin-whitelist" spec="1" />
  <access origin="*" />
  <allow-intent href="http://*/*" />
  <allow-intent href="https://*/*" />
  <allow-intent href="tel:*" />
  <allow-intent href="sms:*" />
  <allow-intent href="mailto:*" />
  <allow-intent href="geo:*" />
  <platform name="android">
    <allow-intent href="market:*" />
  </platform>
  <platform name="android">
    <splash src="res/screen/android/splash-land-hdpi.png" density="land-hdpi" />
    <splash src="res/screen/android/splash-land-ldpi.png" density="land-ldpi" />
    <splash src="res/screen/android/splash-land-mdpi.png" density="land-mdpi" />
    <splash src="res/screen/android/splash-land-xhdpi.png" density="land-xhdpi" />

    <splash src="res/screen/android/splash-port-hdpi.png" density="port-hdpi" />
    <splash src="res/screen/android/splash-port-ldpi.png" density="port-ldpi" />
    <splash src="res/screen/android/splash-port-mdpi.png" density="port-mdpi" />
    <splash src="res/screen/android/splash-port-xhdpi.png" density="port-xhdpi" />
  </platform>

  <platform name="ios">
    <allow-intent href="itms:*" />
    <allow-intent href="itms-apps:*" />
  </platform>
  <preference name="AutoHideSplashScreen" value="true" />
  <preference name="SplashScreenDelay" value="10000" />
  <engine name="android" spec="^7.0.0" />
  <plugin name="cordova-plugin-splashscreen" spec="https://github.com/apache/cordova-plugin-splashscreen.git" />
</widget>

Solution

  • There are a few things you need to change:

    1) Change the plugin line to:

    <plugin name="cordova-plugin-splashscreen" spec="4.1.0" />
    

    The version 4.1.0 is just an example, so change to whatever version you will actually be using.

    2) It is recommended to include a platform independent splash screen, just like a fallback:

    <splash src="splash.png" />
    

    You will need to put the image in the root folder.

    3) Use qualifier instead of density for Android. Example:

    <splash src="res/screen/android/splash-land-hdpi.png" qualifier="land-hdpi"/>
    

    4) You didn't specify the splash screens for iOS. Perhaps you plan to add them after you succeed with Android, but here is an example:

    <splash src="res/screen/ios/Default~iphone.png" width="320" height="480" />