Android splash screen - Image from SD card?

久未见 提交于 2020-01-03 01:43:09

问题


I've been playing around with android and some phonegap code for the last week and through stumbling around, have been quite successful in my application creation.

My app loads using a default splash screen and then calls out to various JSON feeds to download a local copy of all the data required. In doing this it also checks to see if there is an updated version of the splash screen image (Which is editable from a CMS website). If there is, then it downloads it and stores in on to the SD card. This works perfectly.

The problem I then have is the next time the app is loaded I want to show the new splash screen. My code below checks to see if the newer one exists but I don't know the code to then replace the default with the new one :(

My code so far is:

package com.interdirect.Harlequin;

import java.io.File;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;

import com.phonegap.*; 

public class App extends DroidGap {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); 

    String newFolder = "/Harlequin";
    String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
    File appDirectory = new File(extStorageDirectory + newFolder);
    appDirectory.mkdirs();          
    File f = new File(extStorageDirectory + newFolder + "/Images/splash.jpg"); 
    if (f.exists()){     
        //USE THE FILE ABOVE AS THE SPLASH
    }else{       
        super.setIntegerProperty("splashscreen", R.drawable.splash);    
    }        
    super.loadUrl("file:///android_asset/www/index.html",2000);    


};
};

If anyone could help on the above it would awesome as I'm pulling my hair out on something I don't even know if possible :(


回答1:


You can try something like this

Bitmap image = BitmapFactory.decodeFile(f);
ImageView splashScreen = (ImageView)findViewById(R.id.splashscreen);
splashScreen.setImageBitmap(image);


来源:https://stackoverflow.com/questions/6098602/android-splash-screen-image-from-sd-card

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!