I am currently making an application for the Android SDK that will allow me to open/copy a database already made outside of the application. I was having trouble getting my prog
Android by default compresses files with the size greater than 1MB. Older versions of Android OS has a bug, which causes compressed resource files to be read incorrectly.The easiest solution is to use resource file extensions, for example, ".mp3"
Logcat shows the directory doesn't exist. Which is no surprise as there typically isn't a scratch directory under root on android devices.
It's also best to avoid using absolute path names as well as you can't be certain that they'll always exist on the different devices your app may run on. The correct way to access files for your application would be to use Environment when opening a file. For example:
File file = new File(Environment.getExternalStorageDirectory() + "/scratch/os.sqlite");
This would typically exist on the sdcard or a soft linked directory designated as the "sd card" on internal memory. So this example would open a file on the sdcard under the scratch directory.
How to get your database file on to the device or emulator is up to you. You can use the file explorer to push the file into the appropriate directory if you're using the emulator.
Add this permission to your project
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
I responded to an answer given to me on another question and rewrote my code using two separate classes, and Adapter and a Helper, which turned out to work perfectly. I am providing the link to the code in case anyone else is having trouble with developing an SQLiteDatabase like I did.
As far as I can remember, there is no "scratch" directory in the Android filesystem. When you call
File file = new File("/scratch/android-sdk-linux/tools/os.sqlite");
database = SQLiteDatabase.openOrCreateDatabase(file, null);
I believe that the second statement would throw some error as the /scratch/android-sdk-linux/tools/os.sqlite
filepath doesn't exist. Try calling file.mkdirs()
or file.createNewFile()
.