Android打开存储卡,android打开存储卡(TF卡SD卡)中的sqlite文件

android的SDK直接支持sqlite3的API。

打开SD卡上面的sqlite数据库,不需要SQLiteOpenHelper的继承类。只需要,SQLiteDatabase中的一些静态方法。如:

openDatabase(String, CursorFactory, int)

openOrCreateDatabase(File, CursorFactory)

openOrCreateDatabase(String, CursorFactory)

其实openOrCreateDatabase都是调用的openDatabase这个基本的方法。

API的原文描述:public static SQLiteDatabase openDatabase

Sets the locale of the database to the the system's current locale. Call

参数pathto database file to open and/or create

factoryan optional factory class that is called to instantiate a cursor when query is called, or null for default

flagsto control database access mode

返回the newly opened database

抛出if the database cannot be opened

我稍微解释一下。这个方法有三个参数

第一个是path,就是sqlite的绝对路径。

第二个关于记录集的

第三个是标记flag,就是打开方式。例如指示是只读打开,读写方式打开等等,还是自动创建的方式打开。其实openOrCreateDatabase就是在这个flag值为CREATE_IF_NECESSARY。具体可以看API说明Equivalent to openDatabase(path, factory, CREATE_IF_NECESSARY, errorHandler).

public static SQLiteDatabase openOrCreateDatabase (String path, SQLiteDatabase.CursorFactory factory)

Equivalent to openDatabase(path, factory, CREATE_IF_NECESSARY).

public static SQLiteDatabase openOrCreateDatabase (File file, SQLiteDatabase.CursorFactory factory)

Equivalent to openDatabase(file.getPath(), factory, CREATE_IF_NECESSARY).

但是我在使用openDatabase这个函数的,flag使用的OPEN_READONLY,发生错误“No such table android_metadata”。

我搜索之后发现在flag这一参数要传入 NO_LOCALIZED_COLLATORS 。看了API,好像是忽略本地化校验。因为我没有android的这方面的背景知识,也没有在网上搜过更详细的解释。所以也没理解透。API对这个常量的原文解释是:

public static final int NO_LOCALIZED_COLLATORS

Flag for

This causes the collator LOCALIZED not to be created. You must be consistent when using this flag to use the setting the database was created with. If this is set,

Constant Value: 16 (0x00000010)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值