如何从Xamarin中的本地受保护的SQLite DB中读取数据 - Android

时间:2016-11-30 21:34:03

标签: c# android sqlite xamarin local-database

我有以下2个函数用于从现有的SQLite DB中读取数据并且它的工作正常,但我的问题是如何从现有的带有密码的Protected SQLite DB中读取?

        private string GetSQLiteDBPath()
    {
        return Path.Combine(DB_PATH, DB_NAME);
    }
      public override SQLiteDatabase WritableDatabase
    {
        get
        {
            return CreateSQLiteDB();
        }
    }

    private SQLiteDatabase CreateSQLiteDB()
    {
        SQLiteDatabase sqliteDB = null;
        string path = GetSQLiteDBPath();
        Stream streamSQLite = null;
        FileStream streamWriter = null;
        Boolean isSQLiteInit = false;
        try
        {
            if (File.Exists(path))
                isSQLiteInit = true;
            else
            {
                streamSQLite = context.Resources.OpenRawResource(Resource.Raw.DBStore);
                streamWriter = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
                if (streamSQLite != null && streamWriter != null)
                {
                    if (CopySQLiteDB(streamSQLite, streamWriter))
                        isSQLiteInit = true;
                }
            }
            if (isSQLiteInit)
                sqliteDB = SQLiteDatabase.OpenDatabase(path, null, DatabaseOpenFlags.OpenReadonly);
        }
        catch { }
        return sqliteDB;
    }

0 个答案:

没有答案