我正在开发一个Android应用程序,我正在使用Sqlite数据库来存储一些位图。我想要在用户安装应用程序时自动插入一些图像。SQLite - 是否可以通过插入语句插入BLOB?
我使用SQLiteOpenHelper类是这样的:
public class DatabaseHelper extends SQLiteOpenHelper {
...
DatabaseHelper(Context context, String nameOfDB, int version, String[] scriptSQLCreate,
String scriptSQLDelete) {
super(context, nameOfDB, null, version);
this.scriptSQLCreate = scriptSQLCreate;
this.scriptSQLDelete = scriptSQLDelete;
}
@Override
public void onCreate(SQLiteDatabase db) {
int numScripts = scriptSQLCreate.length;
for(int i = 0; i<numScripts; i++){
Log.i(TAG,"Creating database, executing script " + i);
db.execSQL(scriptSQLCreate[i]);
}
}
}
...
我想一个常数通过上面所显示的scriptSQLCreate参数会像这样:
private static final String[] SCRIPT_DATABASE_CREATE = {
"create table memes( id integer primary key autoincrement," +
+ " img blob not null," +
+ " name text not null unique)" ,
"insert into memes(img,name) values(BITMAP1,'1.jpg')",
"insert into memes(img,name) values(BITMAP2,'2.jpg')",
"insert into memes(img,name) values(BITMAP3,'3.jpg')"}
}
任何帮助将大大降低,
THX, 图略赞恩
Humm,你的方法绝对有趣。如果需要用数百个位图预先填充数据库,而不是少数几个,则更是如此。在这种情况下,拥有数百个插入语句变得非常不切实际。我会测试你的方法,但首先我必须想出一个解决所有这些图像的问题的解决方案。在他们中有很多的情况下,只是把它们放在可绘制的文件夹中似乎也是非常不切实际的 – tulio84z 2012-01-16 18:46:13
你想要的是你的项目中的资产目录---有一个API可以让你在那里访问文件,重新在文件系统上的真实文件:http://developer.android.com/reference/android/content/res/AssetManager.html – 2012-01-17 10:31:04