Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I hope you running on the Phone directly, The Phone will n't allow to access the data folders. </p> <ol> <li>Create our own Folder</li> <li>copy the db into the location</li> <li>Open the DB from that location </li> </ol> <p>For the reference </p> <pre><code>public void createDataBase() throws IOException { String path=mContext.getDir("Folder_Name", Context.MODE_WORLD_WRITEABLE).getAbsolutePath(); DB_PATH=path; boolean mDataBaseExist = checkDataBase(); if(!mDataBaseExist) { try { copyDataBase(); } catch (IOException mIOException) { Log.d("Exception",mIOException.getMessage()); throw new Error("ErrorCopyingDataBase"); } } } private boolean checkDataBase() { Log.d(TAG, "In checkDataBase :::::"); File dbFile = new File( DB_PATH+DATABASE_NAME); Log.d("dbFile", dbFile + " "+ dbFile.exists()); return dbFile.exists(); } //Copy the database from assets private void copyDataBase() throws IOException { Log.d(TAG, "In copyDataBase :::::"); InputStream mInput = mContext.getAssets().open(DB_NAME); String outFileName = DB_PATH + DATABASE_NAME; Log.d(TAG, "In copyDataBase outFileName:::::"+outFileName); OutputStream mOutput = new FileOutputStream(outFileName); byte[] mBuffer = new byte[1024]; int mLength; while ((mLength = mInput.read(mBuffer))&gt;0) { mOutput.write(mBuffer, 0, mLength); } mOutput.flush(); mOutput.close(); mInput.close(); } //Open the database, so we can query it public boolean openDataBase() throws SQLException { //DB_PATH + String mPath = DB_PATH+ DATABASE_NAME; Log.v("mPath", mPath); mDataBase = SQLiteDatabase.openDatabase(mPath, null, SQLiteDatabase.CREATE_IF_NECESSARY); return mDataBase != null; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload