Androidフォルダ構造の既存のsqlliteデータベースをどこに配置しますか? drawable フォルダですか、layout フォルダですか。
私はこれに対する解決策を見つけていません。
どんな助けでも大歓迎です。
フォルダに入れる必要がありassets
ます。このようにして、それがあなたのapkに添付されることを確認できます. これは、assets フォルダーから作業ディレクトリにデータベース ファイルをコピーする方法です。
private void copyDataBase() throws IOException{
//Open your local db as the input stream
InputStream myInput = myContext.getAssets().open(DB_NAME);
// Path to the just created empty db
String outFileName = DB_PATH + DB_NAME;
//Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);
//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
//Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
}
次に、ディレクトリからデータベースを読み取ります。
public void openDataBase() throws SQLException{
//Open the database
String myPath = DB_PATH + DB_NAME;
myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
}
パス: data -> data -> com.yourcompany.yourappid -> databases または、Astro File Manager アプリケーションを使用して、デバイス上のデータベースを検索し、デバイスのフォルダー構造を参照できます。
このコードは、デバイス上で SQL の DB ファイルを見つける方法を示しています。
var dbName = 'dbData';
var dbPath;
var dbFile;
if ( Ti.Platform.osname == 'android' ) {
dbPath = 'file:///data/data/' + Ti.App.getID() + '/databases/';
dbFile = Ti.Filesystem.getFile( dbPath + dbName );
}
else {
dbPath = Ti.Filesystem.applicationSupportDirectory + '/database/';
dbFile = Ti.Filesystem.getFile( dbPath + dbName + '.sql' );
}