Interaction with external SQLite databases from Android.

I am trying to work with a web service (which I do not control) that returns the SQLite database when it is requested. Is there any way to do this?

+3
source share
2 answers

I am working on a project that does something similar. I request database updates and depending on the amount of updates needed, it either sends a completely new database or a series of SQL statements. I would highly recommend storing databases on an SD card if available, especially if the size of the databases you download is variable and only a few kilobytes in size.

, ( , XML SOAP, .)

fileStream = new FileOutputStream(new File(I-build-my-filename-stuff-above-here));

/* fileData is a byte[8192] */
while((i = httpResponse.read(fileData)) > -1) {
    fileStream.write(fileData, 0, i);

    position += i;

    if (item.getUpdateType() == UpdateItem.FULL_FILE) {
        progress = position / item.getSize();
    } else {
        progress = position / (item.getSize() * 2);
    }

    item.setProgress(progress);
} // end loop through getting http response stream

fileStream.close();
httpResponse.close();

. iPhone, , Android, SQLiteDatabase.NO_LOCALIZED_COLLATORS. , Database SQLiteOpenHelper:

public Database(Context context, String fileName, String title) {
    super(context, fileName, null, 1);
    this.context = context;
    this.title = title;
    this.fileName = fileName;

    if (fileName != null && fileName.contains("/sdcard")) {
        db = SQLiteDatabase.openDatabase(fileName, null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.CREATE_IF_NECESSARY);            
    } else {
        db = getWritableDatabase();
    }

}
+5

Source: https://habr.com/ru/post/1713122/


All Articles