is there any way, how to create and use database from SD card in my app instead of /data/data/com.myapp/databases directory? I know is it unsecure, but are there any special restrict开发者_运维百科ion like "database on SD card cannot be bigger then 2GB"?
Thanks
Hmyzak
he is a proposed solution which i found in stackoverflow
File dbfile = new File("/sdcard/android/com.myapp/databases/mydatabase.db" );
SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbfile, null);
System.out.println("Its open? " + db.isOpen());
here is the link.
UPDATE
i am not sure you can use this along with SQLiteOpenHelper, but you sure can query the database object.
db.getVersion();
db.execSQL(sql);
db.beginTransaction();
db.endTransaction();
db.setTransactionSuccessful();
db.query(table, columns, selection, selectionArgs, groupBy, having, orderBy);
you can do all the things which you expect with a database. SQLiteOpenHelper in only a wrapper class which helps you the extra which we always can do on our own.
EDIT as for your file size limit i found this link. Is there a file size limit on Android Honeycomb?
You can use this class :
public class ExternalDBHelper extends SQLiteOpenHelper {
public ExternalDBHelper(Context context, String DATABASE_NAME, int DATABASE_VERSION) {
super(context, DirectoryManager.getDir(context, DirectoryManager.ChildDir.Databases, DirectoryManager.ForcePath.SDCard)
+ DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
}
}
Use :
ExternalDBHelper helper = new ExternalDBHelper(context,dbName, CLeitner.Constant.DATABASE_VERSION);
SQLiteDatabase db = helper.getWritableDatabase();
精彩评论