我正在尝试使用一个Web服务(我无法控制),它在您查询时返回一个SQLite数据库.有没有办法做到这一点?
我正在做一个类似的项目.我请求更新数据库,并根据所需的更新量,发送一个全新的数据库或一系列SQL语句.我强烈建议将数据库保留在SD卡上(如果可用),特别是如果您下载的数据库大小可变且超过几千字节.
我正在执行以下操作来获取文件(因为您可能需要在SOAP响应中处理XML,所以也要修改它们,也忽略了进度.)
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();
Run Code Online (Sandbox Code Playgroud)
然后我执行以下操作来访问数据库.由于这些数据库也用于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();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8938 次 |
| 最近记录: |