无法使用SQLiteCipher从SD卡/外部存储更新数据库

时间:2018-11-09 08:34:10

标签: android android-sdcard sqliteopenhelper sqlcipher-android

我想使用SQLiteCipher从sdcard创建数据库,但无法从Device File Explorer中的ExternalStorage / RemovableSDCard中获得更新的日期和时间。

DBHelpers.Java

public class DBHelpers extends SQLiteOpenHelper {

    private static DBHelpers instance;


    public static final int DATABASE_VERSION = 1;
    public static final String DATABASE_NAME = "Data.db";

    private static final String TEXT_TYPE = " TEXT";
    private static final String SQL_CREATE_ENTRIES = ...;

    private static final String SQL_DELETE_ENTRIES =
            "DROP TABLE IF EXISTS " + ...;

    public DBHelpers(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    static public synchronized DBHelpers getInstance(Context context) {
        if (instance == null) {
            instance = new DBHelpers(context);
        }
        return instance;
    }

    public void onCreate(SQLiteDatabase db) {
        db.execSQL(SQL_CREATE_ENTRIES);
    }
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL(SQL_DELETE_ENTRIES);
        onCreate(db);
    }

MainActivity.java

SQliteDatabase database;
SQLiteDatabase.loadLibs(getContext());
String password = "password";
String path = "/storage/sdcard1/";
database = SQLiteDatabase.openOrCreateDatabase(path+"Data.db",password,null);

AndroidManifest.xml

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

0 个答案:

没有答案