Monday, 14 October 2013

PhoneGap Build - Set splash-screen for Android devices

To implement splash screen in android Phonegap its very simple and easy because
HTML5 made it easy for every developers to integrate animation and supportive
screen resolution with the help of html5 and css3 

Here in order to assign simple splash screen all you need is to

1. add a line of code in the java file
import android.os.Bundle;
import org.apache.cordova.*;

  public class Test extends DroidGap {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
    super.setIntegerProperty("splashscreen", R.drawable.splash);
    super.loadUrl("file:///android_asset/www/index.html", 10000);
Here the splashscreen will be in drawable folder so the function
 setIntegerProperty() will set the splash screen
Bcas when ever the android application open it will call the main 
Activity the main activity 
extends Droidgap so the compiler understood that the application 
is webbased and start working
with the client library.
And for android you need to add config.xml in res folder 
and add the folowing code there 
<gap:splash src="img/splash/ios/test.png"  
width="320" height="480" />
<gap:splash src="img/splash/ios/test_at_2x.png"  
width="640" height="960" />
<gap:splash src="img/splash/ios/test_iphone5.png"  
width="640" height="1136" />
<gap:splash src="img/splash/ios/test-Landscape.png" 
 width="1024" height="768" />
<gap:splash src="img/splash/ios/test-Portrait.png" 
 width="768" height="1024" />
<gap:splash src="img/splash/ios/test-vc-Portrait.png" 
 width="1536" height="2008" />
<gap:splash src="img/splash/ios/test-test-Landscape.png"  
width="2048" height="1496" /> 
if you want to add the script add the following 
// Wait for Cordova to load
    document.addEventListener("deviceready", onDeviceReady, false);

    // Cordova is ready
    function onDeviceReady() {;
in the head session after the cordova load 

For android you will need different required sizes than iOS in some cases, 
which you can easily see again by looking at the defaults currently in place 
under the …/platforms/android/res folder within each of the drawable* 
folders as shown in the screenshot below (icon.png files need to be replaced with yours).
 The sizes of the splash screens for Android and how to implement them are
 also explained here in the PhoneGap docs. The splash screens need to be
 placed in the …/platforms/res/drawable folder

No comments:

Post a Comment