首页 文章

使用给定密码以编程方式打开受密码保护的SQLite数据库

提问于
浏览
0

我有一个受密码保护的SQLite数据库 . 我知道密码,让我们说它是 123456qwAS .

我想将此密码嵌入我的应用程序,以便我的应用程序可以自动打开数据库 . 在此数据库受密码保护之前,我使用以下代码打开数据库:

public void showWordlist()
{
    edWord.setEnabled(true);
    String word = edWord.getText().toString();
    Uri uri = Uri.parse("content://myapp_Provider/dict/" + mDBFile.fileName + "/list/" + word);
    edWord.requestFocus();      
    try
    {
        @SuppressWarnings("deprecation")
        Cursor result = managedQuery(uri,null,null,null,null);          
        if (result != null)
        {
            int countRow=result.getCount();
            Log.i(MAIN_TAG, "countRow = " + countRow);
            mLSTCurrentWord.clear();
            //mLSTCurrentContent.clear();
            mLSTCurrentWordId.clear();
            mAdapter.clear();
            if (countRow >= 1)
            {
                int indexWordColumn = result.getColumnIndex("word");
                int indexIdColumn = result.getColumnIndex("id");
                result.moveToFirst();
                String strWord;
                int intId;

                int i = 0;
                do
                {
                    strWord = Utility.decodeContent(result.getString(indexWordColumn));
                    intId = result.getInt(indexIdColumn);
                    mLSTCurrentWord.add(i,strWord);
                    mLSTCurrentWordId.add(i,intId);
                    mAdapter.add(strWord);
                    i++;
                } while (result.moveToNext()); 
            }       
            result.close();
        }
        lstWord.setAdapter(mAdapter);
    }
    catch (Exception ex)
    {
        Log.e(MAIN_TAG, "Error = " + ex.toString());  
    }
    edWord.setEnabled(true);        
}

所以它涉及到我的问题: How can I programmatically add the above password to this code so that my app can open (and load) the password-protected database automatically?

1 回答

  • 0

    Android不支持加密/受密码保护的SQLite操作 . 作为替代方案,您可以集成声称提供此类保护的H2 Database,其成本几乎为1MB .

相关问题