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 (String path, SQLiteDatabase.CursorFactory factory, int flags)

引入自: API 级别1

Open the database according to the flags OPEN_READWRITE OPEN_READONLY CREATE_IF_NECESSARY and/or NO_LOCALIZED_COLLATORS.

Sets the locale of the database to the the system's current locale. Call setLocale(Locale) if you would like something else.

 

参数
path to database file to open and/or create
factory an optional factory class that is called to instantiate a cursor when query is called, or null for default
flags to control database access mode
返回
  • the newly opened database
抛出
SQLiteException if the database cannot be opened

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

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

第二个关于记录集的

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

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

引入自:API 级别11

Equivalent to openDatabase(path, factory, CREATE_IF_NECESSARY, errorHandler).

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

引入自:API 级别1

Equivalent to openDatabase(path, factory, CREATE_IF_NECESSARY).

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

引入自:API 级别1

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

引入自: API 级别1

Flag for openDatabase(String, SQLiteDatabase.CursorFactory, int) to open the database without support for localized collators.

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, setLocale(Locale) will do nothing.

Constant Value: 16 (0x00000010)

更多相关文章

  1. GitHub 标星 2.5K+!教你通过玩游戏的方式学习 VIM!
  2. Android无需申请权限拨打电话的两种方式
  3. 在命令行中通过adb shell am broadcast发送广播通知
  4. Android(安卓)实现图片圆角
  5. Android中的onActivityResult和setResult方法的使用
  6. Android简单模糊背景和圆形ImageView
  7. android 获取一个apk的信息
  8. Android周笔记(9.8-14)(持续更新)
  9. Android:多个Activity和Intent

随机推荐

  1. Android相对布局实现各种梅花效果
  2. android:layout_gravity 和 android:grav
  3. 完整安卓 Android开发视频教程共10季,迅雷
  4. 有关Android手机软件详细分析
  5. iPhone和Android(安卓)UI模式比较列表
  6. 基于Android(安卓)平台简易即时通讯的研
  7. [转]android:layout_gravity 和 android:
  8. Android系列教程(3):Android(安卓)SDK中常用
  9. Android面试题集(2019-04-04总结)
  10. Android(安卓)系统及framework 概述