2011-05-23 48 views
1

我一直在玩android和上週的一些phonegap代碼,並通過磕磕絆絆,已經在我的應用程序創建中相當成功。Android啓動畫面 - 來自SD卡的圖像?

我的應用程序使用默認啓動屏幕加載,然後調出各種JSON訂閱源以下載所需的所有數據的本地副本。在此過程中,它還會檢查是否存在啓動屏幕圖像的更新版本(可從CMS網站進行編輯)。如果有,則將其下載並存儲到SD卡上。這工作完美。

然後我遇到的問題是下次應用程序加載我想顯示新的啓動畫面。我下面的代碼檢查,看是否較新的一個存在,但我不知道該代碼,然後替換爲新一個:(默認

到目前爲止我的代碼是:

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);  


}; 
}; 

如果任何人都可以幫助在它上面會真棒,因爲我拉我的頭髮上的東西,我甚至不知道如果可能的話:(

回答

1

當我用你的代碼,我可以嘗試這樣的事情

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

嗯得到一些錯誤: ** BitmapFactory類型中的decodeFile(String)方法不適用於參數(File)**,也不適用於參數(File)**,也不適用於此參數**無法解析id或不是字段(在R.id.splashscreen下)* * 有沒有其他想法? – 2011-05-23 14:46:16

+0

嘗試使用路徑而不是decodeFile()的文件。 R.id.splashscreen只是您用作splashscreen的imageview資源的一個示例。 – tsmith 2011-05-23 15:01:53

+0

@Ty Smith:請讓我知道在哪裏可以使用這個imageview,因爲我猜想,不能在super.setIntegerProperty()中使用; – NarendraJi 2013-05-02 08:37:59