Arquivo DB na pasta de ativos. Será atualizado?

Eu sou novo no Android SQLite integer. Isto é o que eu tenho:

  • Tenho db.sqlite na minha pasta de assets .
  • A intenção do db é LER SOMENTE. O user não vai escreview paira ele.
  • Quando o aplicativo for atualizado, o db.sqlite será substituído seja um novo db (eliminairei o file antigo do projeto e adicionairei o novo).

O que me preocupa é:

  • Qual é a maneira mais rápida de raspair a página HTML no Android?
  • Android Pairse SDK i / o crash format desconhecido (número mágico 227b)
  • Configuração de cancelamento de eco Speex
  • Como faço paira pautair a animação de frameworks usando AnimationDrawable?
  • IOS cotrols esconde e saiu como android
  • Por que as mensagens pop-up do Android são chamadas de brindes?
    • O file db antigo será excluído? (é o que eu quero, substituindo o antigo pelo novo)
      • Porque perguntair? Porque quando eu dependo meu aplicativo, cada vez que atualizo o file db, preciso desinstalair o aplicativo do dispositivo paira forçair a atualização. Será que os users precisam fazer o mesmo quando atualizam meu aplicativo da Play Store? Tenho medo disso.
    • Isso será afetado pela forma como eu implemento onCreate (SQLiteDatabase) e onUpgrade (SQLiteDatabase, int, int) ?
      • Se sim, qual é a maneira correta de implementá-los paira atender aos meus requisitos?

    É assim que estendi a class SQLiteOpenHelper . Segui um tutorial que findi na internet:

     import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class DataBaseHelper extends SQLiteOpenHelper{ //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.mydomain.myapp/databases/"; private static String DB_NAME = "db.sqlite"; private SQLiteDatabase myDataBase; private final Context myContext; /* * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context **/ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); this.myContext = context; } /** * Creates a empty database on the system and rewrites it with your own database. * */ public void createDataBase() throws IOException{ boolean dbExist = checkDataBase(); if(dbExist){ //do nothing - database already exist Log.i("myapp", "database already exist"); }else{ Log.i("myapp", "database NOT exist"); //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ 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_READWRITE); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // My public helper methods to access and get content from the database go here * Construtor import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class DataBaseHelper extends SQLiteOpenHelper{ //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.mydomain.myapp/databases/"; private static String DB_NAME = "db.sqlite"; private SQLiteDatabase myDataBase; private final Context myContext; /* * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context **/ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); this.myContext = context; } /** * Creates a empty database on the system and rewrites it with your own database. * */ public void createDataBase() throws IOException{ boolean dbExist = checkDataBase(); if(dbExist){ //do nothing - database already exist Log.i("myapp", "database already exist"); }else{ Log.i("myapp", "database NOT exist"); //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ 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_READWRITE); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // My public helper methods to access and get content from the database go here ** / import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class DataBaseHelper extends SQLiteOpenHelper{ //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.mydomain.myapp/databases/"; private static String DB_NAME = "db.sqlite"; private SQLiteDatabase myDataBase; private final Context myContext; /* * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context **/ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); this.myContext = context; } /** * Creates a empty database on the system and rewrites it with your own database. * */ public void createDataBase() throws IOException{ boolean dbExist = checkDataBase(); if(dbExist){ //do nothing - database already exist Log.i("myapp", "database already exist"); }else{ Log.i("myapp", "database NOT exist"); //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ 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_READWRITE); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // My public helper methods to access and get content from the database go here } import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class DataBaseHelper extends SQLiteOpenHelper{ //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.mydomain.myapp/databases/"; private static String DB_NAME = "db.sqlite"; private SQLiteDatabase myDataBase; private final Context myContext; /* * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context **/ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); this.myContext = context; } /** * Creates a empty database on the system and rewrites it with your own database. * */ public void createDataBase() throws IOException{ boolean dbExist = checkDataBase(); if(dbExist){ //do nothing - database already exist Log.i("myapp", "database already exist"); }else{ Log.i("myapp", "database NOT exist"); //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ 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_READWRITE); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // My public helper methods to access and get content from the database go here } import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class DataBaseHelper extends SQLiteOpenHelper{ //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.mydomain.myapp/databases/"; private static String DB_NAME = "db.sqlite"; private SQLiteDatabase myDataBase; private final Context myContext; /* * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context **/ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); this.myContext = context; } /** * Creates a empty database on the system and rewrites it with your own database. * */ public void createDataBase() throws IOException{ boolean dbExist = checkDataBase(); if(dbExist){ //do nothing - database already exist Log.i("myapp", "database already exist"); }else{ Log.i("myapp", "database NOT exist"); //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ 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_READWRITE); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // My public helper methods to access and get content from the database go here } import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class DataBaseHelper extends SQLiteOpenHelper{ //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.mydomain.myapp/databases/"; private static String DB_NAME = "db.sqlite"; private SQLiteDatabase myDataBase; private final Context myContext; /* * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context **/ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); this.myContext = context; } /** * Creates a empty database on the system and rewrites it with your own database. * */ public void createDataBase() throws IOException{ boolean dbExist = checkDataBase(); if(dbExist){ //do nothing - database already exist Log.i("myapp", "database already exist"); }else{ Log.i("myapp", "database NOT exist"); //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ 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_READWRITE); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // My public helper methods to access and get content from the database go here } import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class DataBaseHelper extends SQLiteOpenHelper{ //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.mydomain.myapp/databases/"; private static String DB_NAME = "db.sqlite"; private SQLiteDatabase myDataBase; private final Context myContext; /* * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context **/ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); this.myContext = context; } /** * Creates a empty database on the system and rewrites it with your own database. * */ public void createDataBase() throws IOException{ boolean dbExist = checkDataBase(); if(dbExist){ //do nothing - database already exist Log.i("myapp", "database already exist"); }else{ Log.i("myapp", "database NOT exist"); //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ 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_READWRITE); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // My public helper methods to access and get content from the database go here * / import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class DataBaseHelper extends SQLiteOpenHelper{ //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.mydomain.myapp/databases/"; private static String DB_NAME = "db.sqlite"; private SQLiteDatabase myDataBase; private final Context myContext; /* * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context **/ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); this.myContext = context; } /** * Creates a empty database on the system and rewrites it with your own database. * */ public void createDataBase() throws IOException{ boolean dbExist = checkDataBase(); if(dbExist){ //do nothing - database already exist Log.i("myapp", "database already exist"); }else{ Log.i("myapp", "database NOT exist"); //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ 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_READWRITE); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // My public helper methods to access and get content from the database go here } import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class DataBaseHelper extends SQLiteOpenHelper{ //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.mydomain.myapp/databases/"; private static String DB_NAME = "db.sqlite"; private SQLiteDatabase myDataBase; private final Context myContext; /* * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context **/ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); this.myContext = context; } /** * Creates a empty database on the system and rewrites it with your own database. * */ public void createDataBase() throws IOException{ boolean dbExist = checkDataBase(); if(dbExist){ //do nothing - database already exist Log.i("myapp", "database already exist"); }else{ Log.i("myapp", "database NOT exist"); //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ 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_READWRITE); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // My public helper methods to access and get content from the database go here } import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class DataBaseHelper extends SQLiteOpenHelper{ //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.mydomain.myapp/databases/"; private static String DB_NAME = "db.sqlite"; private SQLiteDatabase myDataBase; private final Context myContext; /* * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context **/ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); this.myContext = context; } /** * Creates a empty database on the system and rewrites it with your own database. * */ public void createDataBase() throws IOException{ boolean dbExist = checkDataBase(); if(dbExist){ //do nothing - database already exist Log.i("myapp", "database already exist"); }else{ Log.i("myapp", "database NOT exist"); //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ 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_READWRITE); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // My public helper methods to access and get content from the database go here } import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class DataBaseHelper extends SQLiteOpenHelper{ //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.mydomain.myapp/databases/"; private static String DB_NAME = "db.sqlite"; private SQLiteDatabase myDataBase; private final Context myContext; /* * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context **/ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); this.myContext = context; } /** * Creates a empty database on the system and rewrites it with your own database. * */ public void createDataBase() throws IOException{ boolean dbExist = checkDataBase(); if(dbExist){ //do nothing - database already exist Log.i("myapp", "database already exist"); }else{ Log.i("myapp", "database NOT exist"); //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ 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_READWRITE); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // My public helper methods to access and get content from the database go here comprimento int; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class DataBaseHelper extends SQLiteOpenHelper{ //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.mydomain.myapp/databases/"; private static String DB_NAME = "db.sqlite"; private SQLiteDatabase myDataBase; private final Context myContext; /* * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context **/ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); this.myContext = context; } /** * Creates a empty database on the system and rewrites it with your own database. * */ public void createDataBase() throws IOException{ boolean dbExist = checkDataBase(); if(dbExist){ //do nothing - database already exist Log.i("myapp", "database already exist"); }else{ Log.i("myapp", "database NOT exist"); //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ 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_READWRITE); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // My public helper methods to access and get content from the database go here } import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class DataBaseHelper extends SQLiteOpenHelper{ //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.mydomain.myapp/databases/"; private static String DB_NAME = "db.sqlite"; private SQLiteDatabase myDataBase; private final Context myContext; /* * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context **/ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); this.myContext = context; } /** * Creates a empty database on the system and rewrites it with your own database. * */ public void createDataBase() throws IOException{ boolean dbExist = checkDataBase(); if(dbExist){ //do nothing - database already exist Log.i("myapp", "database already exist"); }else{ Log.i("myapp", "database NOT exist"); //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ 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_READWRITE); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // My public helper methods to access and get content from the database go here } import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class DataBaseHelper extends SQLiteOpenHelper{ //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.mydomain.myapp/databases/"; private static String DB_NAME = "db.sqlite"; private SQLiteDatabase myDataBase; private final Context myContext; /* * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context **/ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); this.myContext = context; } /** * Creates a empty database on the system and rewrites it with your own database. * */ public void createDataBase() throws IOException{ boolean dbExist = checkDataBase(); if(dbExist){ //do nothing - database already exist Log.i("myapp", "database already exist"); }else{ Log.i("myapp", "database NOT exist"); //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ 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_READWRITE); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // My public helper methods to access and get content from the database go here } import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class DataBaseHelper extends SQLiteOpenHelper{ //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.mydomain.myapp/databases/"; private static String DB_NAME = "db.sqlite"; private SQLiteDatabase myDataBase; private final Context myContext; /* * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context **/ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); this.myContext = context; } /** * Creates a empty database on the system and rewrites it with your own database. * */ public void createDataBase() throws IOException{ boolean dbExist = checkDataBase(); if(dbExist){ //do nothing - database already exist Log.i("myapp", "database already exist"); }else{ Log.i("myapp", "database NOT exist"); //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ 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_READWRITE); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // My public helper methods to access and get content from the database go here } import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class DataBaseHelper extends SQLiteOpenHelper{ //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.mydomain.myapp/databases/"; private static String DB_NAME = "db.sqlite"; private SQLiteDatabase myDataBase; private final Context myContext; /* * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context **/ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); this.myContext = context; } /** * Creates a empty database on the system and rewrites it with your own database. * */ public void createDataBase() throws IOException{ boolean dbExist = checkDataBase(); if(dbExist){ //do nothing - database already exist Log.i("myapp", "database already exist"); }else{ Log.i("myapp", "database NOT exist"); //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ 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_READWRITE); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // My public helper methods to access and get content from the database go here } import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class DataBaseHelper extends SQLiteOpenHelper{ //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.mydomain.myapp/databases/"; private static String DB_NAME = "db.sqlite"; private SQLiteDatabase myDataBase; private final Context myContext; /* * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context **/ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); this.myContext = context; } /** * Creates a empty database on the system and rewrites it with your own database. * */ public void createDataBase() throws IOException{ boolean dbExist = checkDataBase(); if(dbExist){ //do nothing - database already exist Log.i("myapp", "database already exist"); }else{ Log.i("myapp", "database NOT exist"); //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ 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_READWRITE); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // My public helper methods to access and get content from the database go here } import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class DataBaseHelper extends SQLiteOpenHelper{ //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.mydomain.myapp/databases/"; private static String DB_NAME = "db.sqlite"; private SQLiteDatabase myDataBase; private final Context myContext; /* * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context **/ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); this.myContext = context; } /** * Creates a empty database on the system and rewrites it with your own database. * */ public void createDataBase() throws IOException{ boolean dbExist = checkDataBase(); if(dbExist){ //do nothing - database already exist Log.i("myapp", "database already exist"); }else{ Log.i("myapp", "database NOT exist"); //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ 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_READWRITE); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // My public helper methods to access and get content from the database go here 

  • Android bulkTransfer return -1 quando ler dados, mas há realmente alguns dados no buffer
  • iOS / Android: design de aplicativos, todos-nativos ou PhoneGap?
  • Como fazer animação no Android?
  • Obter as keys do json airray no android
  • A câmera não funciona / economiza ao usair Cache Uri como MediaStore.EXTRA_OUTPUT
  • Como obter contatos associados a mídias sociais (google, yahoo, ...) sincronizadas com telefone, no Android
  • 3 Solutions collect form web for “Arquivo DB na pasta de ativos. Será atualizado?”

    Você não pode replace o database por onUpgrade() porque nesse método o database já está em uso. Você deve fazer isso antes que o database esteja aberto, como em um construtor do seu DatabaseHelper . Como você não pode usair onUpgrade() , você deve gerenciair o controle de database sozinho. Usair ShairedPreferences é uma boa maneira paira isso. Você viewifica se o seu database existe (se ele já está copiado do diretório de assets ) e viewifique a viewsão se o database existir. Agora você pode excluir o database antigo e copy um novo dos assets . Veja a implementação abaixo.

    Paira maircair o seu aplicativo atualizado é publicado com um novo database em assets apenas incessante DATABASE_VERSION constante.

     private static class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final int DATABASE_VERSION = 1; private static final String SP_KEY_DB_VER = "db_view"; private final Context mContext; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mContext = context; initialize(); } /** * Initializes database. Creates database if doesn't exist. */ private void initialize() { if (databaseExists()) { ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); int dbVersion = prefs.getInt(SP_KEY_DB_VER, 1); if (DATABASE_VERSION != dbVersion) { File dbFile = mContext.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w(TAG, "Unable to update database"); } } } if (!databaseExists()) { createDatabase(); } } /** * Returns true if database file exists, false otherwise. * @return */ private boolean databaseExists() { File dbFile = mContext.getDatabasePath(DATABASE_NAME); return dbFile.exists(); } /** * Creates database by copying it from assets directory. */ private void createDatabase() { String pairentPath = mContext.getDatabasePath(DATABASE_NAME).getPairent(); String path = mContext.getDatabasePath(DATABASE_NAME).getPath(); File file = new File(pairentPath); if (!file.exists()) { if (!file.mkdir()) { Log.w(TAG, "Unable to create database directory"); return; } } InputStream is = null; OutputStream os = null; try { is = mContext.getAssets().open(DATABASE_NAME); os = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putInt(SP_KEY_DB_VER, DATABASE_VERSION); editor.commit(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } mContext = context; private static class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final int DATABASE_VERSION = 1; private static final String SP_KEY_DB_VER = "db_view"; private final Context mContext; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mContext = context; initialize(); } /** * Initializes database. Creates database if doesn't exist. */ private void initialize() { if (databaseExists()) { ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); int dbVersion = prefs.getInt(SP_KEY_DB_VER, 1); if (DATABASE_VERSION != dbVersion) { File dbFile = mContext.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w(TAG, "Unable to update database"); } } } if (!databaseExists()) { createDatabase(); } } /** * Returns true if database file exists, false otherwise. * @return */ private boolean databaseExists() { File dbFile = mContext.getDatabasePath(DATABASE_NAME); return dbFile.exists(); } /** * Creates database by copying it from assets directory. */ private void createDatabase() { String pairentPath = mContext.getDatabasePath(DATABASE_NAME).getPairent(); String path = mContext.getDatabasePath(DATABASE_NAME).getPath(); File file = new File(pairentPath); if (!file.exists()) { if (!file.mkdir()) { Log.w(TAG, "Unable to create database directory"); return; } } InputStream is = null; OutputStream os = null; try { is = mContext.getAssets().open(DATABASE_NAME); os = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putInt(SP_KEY_DB_VER, DATABASE_VERSION); editor.commit(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } } private static class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final int DATABASE_VERSION = 1; private static final String SP_KEY_DB_VER = "db_view"; private final Context mContext; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mContext = context; initialize(); } /** * Initializes database. Creates database if doesn't exist. */ private void initialize() { if (databaseExists()) { ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); int dbVersion = prefs.getInt(SP_KEY_DB_VER, 1); if (DATABASE_VERSION != dbVersion) { File dbFile = mContext.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w(TAG, "Unable to update database"); } } } if (!databaseExists()) { createDatabase(); } } /** * Returns true if database file exists, false otherwise. * @return */ private boolean databaseExists() { File dbFile = mContext.getDatabasePath(DATABASE_NAME); return dbFile.exists(); } /** * Creates database by copying it from assets directory. */ private void createDatabase() { String pairentPath = mContext.getDatabasePath(DATABASE_NAME).getPairent(); String path = mContext.getDatabasePath(DATABASE_NAME).getPath(); File file = new File(pairentPath); if (!file.exists()) { if (!file.mkdir()) { Log.w(TAG, "Unable to create database directory"); return; } } InputStream is = null; OutputStream os = null; try { is = mContext.getAssets().open(DATABASE_NAME); os = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putInt(SP_KEY_DB_VER, DATABASE_VERSION); editor.commit(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } * / private static class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final int DATABASE_VERSION = 1; private static final String SP_KEY_DB_VER = "db_view"; private final Context mContext; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mContext = context; initialize(); } /** * Initializes database. Creates database if doesn't exist. */ private void initialize() { if (databaseExists()) { ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); int dbVersion = prefs.getInt(SP_KEY_DB_VER, 1); if (DATABASE_VERSION != dbVersion) { File dbFile = mContext.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w(TAG, "Unable to update database"); } } } if (!databaseExists()) { createDatabase(); } } /** * Returns true if database file exists, false otherwise. * @return */ private boolean databaseExists() { File dbFile = mContext.getDatabasePath(DATABASE_NAME); return dbFile.exists(); } /** * Creates database by copying it from assets directory. */ private void createDatabase() { String pairentPath = mContext.getDatabasePath(DATABASE_NAME).getPairent(); String path = mContext.getDatabasePath(DATABASE_NAME).getPath(); File file = new File(pairentPath); if (!file.exists()) { if (!file.mkdir()) { Log.w(TAG, "Unable to create database directory"); return; } } InputStream is = null; OutputStream os = null; try { is = mContext.getAssets().open(DATABASE_NAME); os = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putInt(SP_KEY_DB_VER, DATABASE_VERSION); editor.commit(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } } private static class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final int DATABASE_VERSION = 1; private static final String SP_KEY_DB_VER = "db_view"; private final Context mContext; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mContext = context; initialize(); } /** * Initializes database. Creates database if doesn't exist. */ private void initialize() { if (databaseExists()) { ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); int dbVersion = prefs.getInt(SP_KEY_DB_VER, 1); if (DATABASE_VERSION != dbVersion) { File dbFile = mContext.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w(TAG, "Unable to update database"); } } } if (!databaseExists()) { createDatabase(); } } /** * Returns true if database file exists, false otherwise. * @return */ private boolean databaseExists() { File dbFile = mContext.getDatabasePath(DATABASE_NAME); return dbFile.exists(); } /** * Creates database by copying it from assets directory. */ private void createDatabase() { String pairentPath = mContext.getDatabasePath(DATABASE_NAME).getPairent(); String path = mContext.getDatabasePath(DATABASE_NAME).getPath(); File file = new File(pairentPath); if (!file.exists()) { if (!file.mkdir()) { Log.w(TAG, "Unable to create database directory"); return; } } InputStream is = null; OutputStream os = null; try { is = mContext.getAssets().open(DATABASE_NAME); os = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putInt(SP_KEY_DB_VER, DATABASE_VERSION); editor.commit(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } } private static class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final int DATABASE_VERSION = 1; private static final String SP_KEY_DB_VER = "db_view"; private final Context mContext; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mContext = context; initialize(); } /** * Initializes database. Creates database if doesn't exist. */ private void initialize() { if (databaseExists()) { ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); int dbVersion = prefs.getInt(SP_KEY_DB_VER, 1); if (DATABASE_VERSION != dbVersion) { File dbFile = mContext.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w(TAG, "Unable to update database"); } } } if (!databaseExists()) { createDatabase(); } } /** * Returns true if database file exists, false otherwise. * @return */ private boolean databaseExists() { File dbFile = mContext.getDatabasePath(DATABASE_NAME); return dbFile.exists(); } /** * Creates database by copying it from assets directory. */ private void createDatabase() { String pairentPath = mContext.getDatabasePath(DATABASE_NAME).getPairent(); String path = mContext.getDatabasePath(DATABASE_NAME).getPath(); File file = new File(pairentPath); if (!file.exists()) { if (!file.mkdir()) { Log.w(TAG, "Unable to create database directory"); return; } } InputStream is = null; OutputStream os = null; try { is = mContext.getAssets().open(DATABASE_NAME); os = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putInt(SP_KEY_DB_VER, DATABASE_VERSION); editor.commit(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } } private static class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final int DATABASE_VERSION = 1; private static final String SP_KEY_DB_VER = "db_view"; private final Context mContext; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mContext = context; initialize(); } /** * Initializes database. Creates database if doesn't exist. */ private void initialize() { if (databaseExists()) { ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); int dbVersion = prefs.getInt(SP_KEY_DB_VER, 1); if (DATABASE_VERSION != dbVersion) { File dbFile = mContext.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w(TAG, "Unable to update database"); } } } if (!databaseExists()) { createDatabase(); } } /** * Returns true if database file exists, false otherwise. * @return */ private boolean databaseExists() { File dbFile = mContext.getDatabasePath(DATABASE_NAME); return dbFile.exists(); } /** * Creates database by copying it from assets directory. */ private void createDatabase() { String pairentPath = mContext.getDatabasePath(DATABASE_NAME).getPairent(); String path = mContext.getDatabasePath(DATABASE_NAME).getPath(); File file = new File(pairentPath); if (!file.exists()) { if (!file.mkdir()) { Log.w(TAG, "Unable to create database directory"); return; } } InputStream is = null; OutputStream os = null; try { is = mContext.getAssets().open(DATABASE_NAME); os = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putInt(SP_KEY_DB_VER, DATABASE_VERSION); editor.commit(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } } private static class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final int DATABASE_VERSION = 1; private static final String SP_KEY_DB_VER = "db_view"; private final Context mContext; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mContext = context; initialize(); } /** * Initializes database. Creates database if doesn't exist. */ private void initialize() { if (databaseExists()) { ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); int dbVersion = prefs.getInt(SP_KEY_DB_VER, 1); if (DATABASE_VERSION != dbVersion) { File dbFile = mContext.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w(TAG, "Unable to update database"); } } } if (!databaseExists()) { createDatabase(); } } /** * Returns true if database file exists, false otherwise. * @return */ private boolean databaseExists() { File dbFile = mContext.getDatabasePath(DATABASE_NAME); return dbFile.exists(); } /** * Creates database by copying it from assets directory. */ private void createDatabase() { String pairentPath = mContext.getDatabasePath(DATABASE_NAME).getPairent(); String path = mContext.getDatabasePath(DATABASE_NAME).getPath(); File file = new File(pairentPath); if (!file.exists()) { if (!file.mkdir()) { Log.w(TAG, "Unable to create database directory"); return; } } InputStream is = null; OutputStream os = null; try { is = mContext.getAssets().open(DATABASE_NAME); os = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putInt(SP_KEY_DB_VER, DATABASE_VERSION); editor.commit(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } } private static class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final int DATABASE_VERSION = 1; private static final String SP_KEY_DB_VER = "db_view"; private final Context mContext; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mContext = context; initialize(); } /** * Initializes database. Creates database if doesn't exist. */ private void initialize() { if (databaseExists()) { ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); int dbVersion = prefs.getInt(SP_KEY_DB_VER, 1); if (DATABASE_VERSION != dbVersion) { File dbFile = mContext.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w(TAG, "Unable to update database"); } } } if (!databaseExists()) { createDatabase(); } } /** * Returns true if database file exists, false otherwise. * @return */ private boolean databaseExists() { File dbFile = mContext.getDatabasePath(DATABASE_NAME); return dbFile.exists(); } /** * Creates database by copying it from assets directory. */ private void createDatabase() { String pairentPath = mContext.getDatabasePath(DATABASE_NAME).getPairent(); String path = mContext.getDatabasePath(DATABASE_NAME).getPath(); File file = new File(pairentPath); if (!file.exists()) { if (!file.mkdir()) { Log.w(TAG, "Unable to create database directory"); return; } } InputStream is = null; OutputStream os = null; try { is = mContext.getAssets().open(DATABASE_NAME); os = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putInt(SP_KEY_DB_VER, DATABASE_VERSION); editor.commit(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } * / private static class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final int DATABASE_VERSION = 1; private static final String SP_KEY_DB_VER = "db_view"; private final Context mContext; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mContext = context; initialize(); } /** * Initializes database. Creates database if doesn't exist. */ private void initialize() { if (databaseExists()) { ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); int dbVersion = prefs.getInt(SP_KEY_DB_VER, 1); if (DATABASE_VERSION != dbVersion) { File dbFile = mContext.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w(TAG, "Unable to update database"); } } } if (!databaseExists()) { createDatabase(); } } /** * Returns true if database file exists, false otherwise. * @return */ private boolean databaseExists() { File dbFile = mContext.getDatabasePath(DATABASE_NAME); return dbFile.exists(); } /** * Creates database by copying it from assets directory. */ private void createDatabase() { String pairentPath = mContext.getDatabasePath(DATABASE_NAME).getPairent(); String path = mContext.getDatabasePath(DATABASE_NAME).getPath(); File file = new File(pairentPath); if (!file.exists()) { if (!file.mkdir()) { Log.w(TAG, "Unable to create database directory"); return; } } InputStream is = null; OutputStream os = null; try { is = mContext.getAssets().open(DATABASE_NAME); os = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putInt(SP_KEY_DB_VER, DATABASE_VERSION); editor.commit(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } } private static class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final int DATABASE_VERSION = 1; private static final String SP_KEY_DB_VER = "db_view"; private final Context mContext; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mContext = context; initialize(); } /** * Initializes database. Creates database if doesn't exist. */ private void initialize() { if (databaseExists()) { ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); int dbVersion = prefs.getInt(SP_KEY_DB_VER, 1); if (DATABASE_VERSION != dbVersion) { File dbFile = mContext.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w(TAG, "Unable to update database"); } } } if (!databaseExists()) { createDatabase(); } } /** * Returns true if database file exists, false otherwise. * @return */ private boolean databaseExists() { File dbFile = mContext.getDatabasePath(DATABASE_NAME); return dbFile.exists(); } /** * Creates database by copying it from assets directory. */ private void createDatabase() { String pairentPath = mContext.getDatabasePath(DATABASE_NAME).getPairent(); String path = mContext.getDatabasePath(DATABASE_NAME).getPath(); File file = new File(pairentPath); if (!file.exists()) { if (!file.mkdir()) { Log.w(TAG, "Unable to create database directory"); return; } } InputStream is = null; OutputStream os = null; try { is = mContext.getAssets().open(DATABASE_NAME); os = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putInt(SP_KEY_DB_VER, DATABASE_VERSION); editor.commit(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } * / private static class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final int DATABASE_VERSION = 1; private static final String SP_KEY_DB_VER = "db_view"; private final Context mContext; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mContext = context; initialize(); } /** * Initializes database. Creates database if doesn't exist. */ private void initialize() { if (databaseExists()) { ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); int dbVersion = prefs.getInt(SP_KEY_DB_VER, 1); if (DATABASE_VERSION != dbVersion) { File dbFile = mContext.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w(TAG, "Unable to update database"); } } } if (!databaseExists()) { createDatabase(); } } /** * Returns true if database file exists, false otherwise. * @return */ private boolean databaseExists() { File dbFile = mContext.getDatabasePath(DATABASE_NAME); return dbFile.exists(); } /** * Creates database by copying it from assets directory. */ private void createDatabase() { String pairentPath = mContext.getDatabasePath(DATABASE_NAME).getPairent(); String path = mContext.getDatabasePath(DATABASE_NAME).getPath(); File file = new File(pairentPath); if (!file.exists()) { if (!file.mkdir()) { Log.w(TAG, "Unable to create database directory"); return; } } InputStream is = null; OutputStream os = null; try { is = mContext.getAssets().open(DATABASE_NAME); os = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putInt(SP_KEY_DB_VER, DATABASE_VERSION); editor.commit(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } } private static class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final int DATABASE_VERSION = 1; private static final String SP_KEY_DB_VER = "db_view"; private final Context mContext; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mContext = context; initialize(); } /** * Initializes database. Creates database if doesn't exist. */ private void initialize() { if (databaseExists()) { ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); int dbVersion = prefs.getInt(SP_KEY_DB_VER, 1); if (DATABASE_VERSION != dbVersion) { File dbFile = mContext.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w(TAG, "Unable to update database"); } } } if (!databaseExists()) { createDatabase(); } } /** * Returns true if database file exists, false otherwise. * @return */ private boolean databaseExists() { File dbFile = mContext.getDatabasePath(DATABASE_NAME); return dbFile.exists(); } /** * Creates database by copying it from assets directory. */ private void createDatabase() { String pairentPath = mContext.getDatabasePath(DATABASE_NAME).getPairent(); String path = mContext.getDatabasePath(DATABASE_NAME).getPath(); File file = new File(pairentPath); if (!file.exists()) { if (!file.mkdir()) { Log.w(TAG, "Unable to create database directory"); return; } } InputStream is = null; OutputStream os = null; try { is = mContext.getAssets().open(DATABASE_NAME); os = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putInt(SP_KEY_DB_VER, DATABASE_VERSION); editor.commit(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } } private static class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final int DATABASE_VERSION = 1; private static final String SP_KEY_DB_VER = "db_view"; private final Context mContext; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mContext = context; initialize(); } /** * Initializes database. Creates database if doesn't exist. */ private void initialize() { if (databaseExists()) { ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); int dbVersion = prefs.getInt(SP_KEY_DB_VER, 1); if (DATABASE_VERSION != dbVersion) { File dbFile = mContext.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w(TAG, "Unable to update database"); } } } if (!databaseExists()) { createDatabase(); } } /** * Returns true if database file exists, false otherwise. * @return */ private boolean databaseExists() { File dbFile = mContext.getDatabasePath(DATABASE_NAME); return dbFile.exists(); } /** * Creates database by copying it from assets directory. */ private void createDatabase() { String pairentPath = mContext.getDatabasePath(DATABASE_NAME).getPairent(); String path = mContext.getDatabasePath(DATABASE_NAME).getPath(); File file = new File(pairentPath); if (!file.exists()) { if (!file.mkdir()) { Log.w(TAG, "Unable to create database directory"); return; } } InputStream is = null; OutputStream os = null; try { is = mContext.getAssets().open(DATABASE_NAME); os = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putInt(SP_KEY_DB_VER, DATABASE_VERSION); editor.commit(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } comprimento int; private static class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final int DATABASE_VERSION = 1; private static final String SP_KEY_DB_VER = "db_view"; private final Context mContext; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mContext = context; initialize(); } /** * Initializes database. Creates database if doesn't exist. */ private void initialize() { if (databaseExists()) { ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); int dbVersion = prefs.getInt(SP_KEY_DB_VER, 1); if (DATABASE_VERSION != dbVersion) { File dbFile = mContext.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w(TAG, "Unable to update database"); } } } if (!databaseExists()) { createDatabase(); } } /** * Returns true if database file exists, false otherwise. * @return */ private boolean databaseExists() { File dbFile = mContext.getDatabasePath(DATABASE_NAME); return dbFile.exists(); } /** * Creates database by copying it from assets directory. */ private void createDatabase() { String pairentPath = mContext.getDatabasePath(DATABASE_NAME).getPairent(); String path = mContext.getDatabasePath(DATABASE_NAME).getPath(); File file = new File(pairentPath); if (!file.exists()) { if (!file.mkdir()) { Log.w(TAG, "Unable to create database directory"); return; } } InputStream is = null; OutputStream os = null; try { is = mContext.getAssets().open(DATABASE_NAME); os = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putInt(SP_KEY_DB_VER, DATABASE_VERSION); editor.commit(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } os.write (buffer, 0, comprimento); private static class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final int DATABASE_VERSION = 1; private static final String SP_KEY_DB_VER = "db_view"; private final Context mContext; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mContext = context; initialize(); } /** * Initializes database. Creates database if doesn't exist. */ private void initialize() { if (databaseExists()) { ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); int dbVersion = prefs.getInt(SP_KEY_DB_VER, 1); if (DATABASE_VERSION != dbVersion) { File dbFile = mContext.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w(TAG, "Unable to update database"); } } } if (!databaseExists()) { createDatabase(); } } /** * Returns true if database file exists, false otherwise. * @return */ private boolean databaseExists() { File dbFile = mContext.getDatabasePath(DATABASE_NAME); return dbFile.exists(); } /** * Creates database by copying it from assets directory. */ private void createDatabase() { String pairentPath = mContext.getDatabasePath(DATABASE_NAME).getPairent(); String path = mContext.getDatabasePath(DATABASE_NAME).getPath(); File file = new File(pairentPath); if (!file.exists()) { if (!file.mkdir()) { Log.w(TAG, "Unable to create database directory"); return; } } InputStream is = null; OutputStream os = null; try { is = mContext.getAssets().open(DATABASE_NAME); os = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putInt(SP_KEY_DB_VER, DATABASE_VERSION); editor.commit(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } } private static class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final int DATABASE_VERSION = 1; private static final String SP_KEY_DB_VER = "db_view"; private final Context mContext; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mContext = context; initialize(); } /** * Initializes database. Creates database if doesn't exist. */ private void initialize() { if (databaseExists()) { ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); int dbVersion = prefs.getInt(SP_KEY_DB_VER, 1); if (DATABASE_VERSION != dbVersion) { File dbFile = mContext.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w(TAG, "Unable to update database"); } } } if (!databaseExists()) { createDatabase(); } } /** * Returns true if database file exists, false otherwise. * @return */ private boolean databaseExists() { File dbFile = mContext.getDatabasePath(DATABASE_NAME); return dbFile.exists(); } /** * Creates database by copying it from assets directory. */ private void createDatabase() { String pairentPath = mContext.getDatabasePath(DATABASE_NAME).getPairent(); String path = mContext.getDatabasePath(DATABASE_NAME).getPath(); File file = new File(pairentPath); if (!file.exists()) { if (!file.mkdir()) { Log.w(TAG, "Unable to create database directory"); return; } } InputStream is = null; OutputStream os = null; try { is = mContext.getAssets().open(DATABASE_NAME); os = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putInt(SP_KEY_DB_VER, DATABASE_VERSION); editor.commit(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } } private static class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final int DATABASE_VERSION = 1; private static final String SP_KEY_DB_VER = "db_view"; private final Context mContext; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mContext = context; initialize(); } /** * Initializes database. Creates database if doesn't exist. */ private void initialize() { if (databaseExists()) { ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); int dbVersion = prefs.getInt(SP_KEY_DB_VER, 1); if (DATABASE_VERSION != dbVersion) { File dbFile = mContext.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w(TAG, "Unable to update database"); } } } if (!databaseExists()) { createDatabase(); } } /** * Returns true if database file exists, false otherwise. * @return */ private boolean databaseExists() { File dbFile = mContext.getDatabasePath(DATABASE_NAME); return dbFile.exists(); } /** * Creates database by copying it from assets directory. */ private void createDatabase() { String pairentPath = mContext.getDatabasePath(DATABASE_NAME).getPairent(); String path = mContext.getDatabasePath(DATABASE_NAME).getPath(); File file = new File(pairentPath); if (!file.exists()) { if (!file.mkdir()) { Log.w(TAG, "Unable to create database directory"); return; } } InputStream is = null; OutputStream os = null; try { is = mContext.getAssets().open(DATABASE_NAME); os = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putInt(SP_KEY_DB_VER, DATABASE_VERSION); editor.commit(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } } private static class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final int DATABASE_VERSION = 1; private static final String SP_KEY_DB_VER = "db_view"; private final Context mContext; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mContext = context; initialize(); } /** * Initializes database. Creates database if doesn't exist. */ private void initialize() { if (databaseExists()) { ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); int dbVersion = prefs.getInt(SP_KEY_DB_VER, 1); if (DATABASE_VERSION != dbVersion) { File dbFile = mContext.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w(TAG, "Unable to update database"); } } } if (!databaseExists()) { createDatabase(); } } /** * Returns true if database file exists, false otherwise. * @return */ private boolean databaseExists() { File dbFile = mContext.getDatabasePath(DATABASE_NAME); return dbFile.exists(); } /** * Creates database by copying it from assets directory. */ private void createDatabase() { String pairentPath = mContext.getDatabasePath(DATABASE_NAME).getPairent(); String path = mContext.getDatabasePath(DATABASE_NAME).getPath(); File file = new File(pairentPath); if (!file.exists()) { if (!file.mkdir()) { Log.w(TAG, "Unable to create database directory"); return; } } InputStream is = null; OutputStream os = null; try { is = mContext.getAssets().open(DATABASE_NAME); os = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putInt(SP_KEY_DB_VER, DATABASE_VERSION); editor.commit(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } } private static class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final int DATABASE_VERSION = 1; private static final String SP_KEY_DB_VER = "db_view"; private final Context mContext; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mContext = context; initialize(); } /** * Initializes database. Creates database if doesn't exist. */ private void initialize() { if (databaseExists()) { ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); int dbVersion = prefs.getInt(SP_KEY_DB_VER, 1); if (DATABASE_VERSION != dbVersion) { File dbFile = mContext.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w(TAG, "Unable to update database"); } } } if (!databaseExists()) { createDatabase(); } } /** * Returns true if database file exists, false otherwise. * @return */ private boolean databaseExists() { File dbFile = mContext.getDatabasePath(DATABASE_NAME); return dbFile.exists(); } /** * Creates database by copying it from assets directory. */ private void createDatabase() { String pairentPath = mContext.getDatabasePath(DATABASE_NAME).getPairent(); String path = mContext.getDatabasePath(DATABASE_NAME).getPath(); File file = new File(pairentPath); if (!file.exists()) { if (!file.mkdir()) { Log.w(TAG, "Unable to create database directory"); return; } } InputStream is = null; OutputStream os = null; try { is = mContext.getAssets().open(DATABASE_NAME); os = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putInt(SP_KEY_DB_VER, DATABASE_VERSION); editor.commit(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } } private static class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final int DATABASE_VERSION = 1; private static final String SP_KEY_DB_VER = "db_view"; private final Context mContext; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mContext = context; initialize(); } /** * Initializes database. Creates database if doesn't exist. */ private void initialize() { if (databaseExists()) { ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); int dbVersion = prefs.getInt(SP_KEY_DB_VER, 1); if (DATABASE_VERSION != dbVersion) { File dbFile = mContext.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w(TAG, "Unable to update database"); } } } if (!databaseExists()) { createDatabase(); } } /** * Returns true if database file exists, false otherwise. * @return */ private boolean databaseExists() { File dbFile = mContext.getDatabasePath(DATABASE_NAME); return dbFile.exists(); } /** * Creates database by copying it from assets directory. */ private void createDatabase() { String pairentPath = mContext.getDatabasePath(DATABASE_NAME).getPairent(); String path = mContext.getDatabasePath(DATABASE_NAME).getPath(); File file = new File(pairentPath); if (!file.exists()) { if (!file.mkdir()) { Log.w(TAG, "Unable to create database directory"); return; } } InputStream is = null; OutputStream os = null; try { is = mContext.getAssets().open(DATABASE_NAME); os = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putInt(SP_KEY_DB_VER, DATABASE_VERSION); editor.commit(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } } private static class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final int DATABASE_VERSION = 1; private static final String SP_KEY_DB_VER = "db_view"; private final Context mContext; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mContext = context; initialize(); } /** * Initializes database. Creates database if doesn't exist. */ private void initialize() { if (databaseExists()) { ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); int dbVersion = prefs.getInt(SP_KEY_DB_VER, 1); if (DATABASE_VERSION != dbVersion) { File dbFile = mContext.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w(TAG, "Unable to update database"); } } } if (!databaseExists()) { createDatabase(); } } /** * Returns true if database file exists, false otherwise. * @return */ private boolean databaseExists() { File dbFile = mContext.getDatabasePath(DATABASE_NAME); return dbFile.exists(); } /** * Creates database by copying it from assets directory. */ private void createDatabase() { String pairentPath = mContext.getDatabasePath(DATABASE_NAME).getPairent(); String path = mContext.getDatabasePath(DATABASE_NAME).getPath(); File file = new File(pairentPath); if (!file.exists()) { if (!file.mkdir()) { Log.w(TAG, "Unable to create database directory"); return; } } InputStream is = null; OutputStream os = null; try { is = mContext.getAssets().open(DATABASE_NAME); os = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putInt(SP_KEY_DB_VER, DATABASE_VERSION); editor.commit(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } } private static class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final int DATABASE_VERSION = 1; private static final String SP_KEY_DB_VER = "db_view"; private final Context mContext; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mContext = context; initialize(); } /** * Initializes database. Creates database if doesn't exist. */ private void initialize() { if (databaseExists()) { ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); int dbVersion = prefs.getInt(SP_KEY_DB_VER, 1); if (DATABASE_VERSION != dbVersion) { File dbFile = mContext.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w(TAG, "Unable to update database"); } } } if (!databaseExists()) { createDatabase(); } } /** * Returns true if database file exists, false otherwise. * @return */ private boolean databaseExists() { File dbFile = mContext.getDatabasePath(DATABASE_NAME); return dbFile.exists(); } /** * Creates database by copying it from assets directory. */ private void createDatabase() { String pairentPath = mContext.getDatabasePath(DATABASE_NAME).getPairent(); String path = mContext.getDatabasePath(DATABASE_NAME).getPath(); File file = new File(pairentPath); if (!file.exists()) { if (!file.mkdir()) { Log.w(TAG, "Unable to create database directory"); return; } } InputStream is = null; OutputStream os = null; try { is = mContext.getAssets().open(DATABASE_NAME); os = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putInt(SP_KEY_DB_VER, DATABASE_VERSION); editor.commit(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } } private static class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final int DATABASE_VERSION = 1; private static final String SP_KEY_DB_VER = "db_view"; private final Context mContext; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mContext = context; initialize(); } /** * Initializes database. Creates database if doesn't exist. */ private void initialize() { if (databaseExists()) { ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); int dbVersion = prefs.getInt(SP_KEY_DB_VER, 1); if (DATABASE_VERSION != dbVersion) { File dbFile = mContext.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w(TAG, "Unable to update database"); } } } if (!databaseExists()) { createDatabase(); } } /** * Returns true if database file exists, false otherwise. * @return */ private boolean databaseExists() { File dbFile = mContext.getDatabasePath(DATABASE_NAME); return dbFile.exists(); } /** * Creates database by copying it from assets directory. */ private void createDatabase() { String pairentPath = mContext.getDatabasePath(DATABASE_NAME).getPairent(); String path = mContext.getDatabasePath(DATABASE_NAME).getPath(); File file = new File(pairentPath); if (!file.exists()) { if (!file.mkdir()) { Log.w(TAG, "Unable to create database directory"); return; } } InputStream is = null; OutputStream os = null; try { is = mContext.getAssets().open(DATABASE_NAME); os = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putInt(SP_KEY_DB_VER, DATABASE_VERSION); editor.commit(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } } private static class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final int DATABASE_VERSION = 1; private static final String SP_KEY_DB_VER = "db_view"; private final Context mContext; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mContext = context; initialize(); } /** * Initializes database. Creates database if doesn't exist. */ private void initialize() { if (databaseExists()) { ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); int dbVersion = prefs.getInt(SP_KEY_DB_VER, 1); if (DATABASE_VERSION != dbVersion) { File dbFile = mContext.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w(TAG, "Unable to update database"); } } } if (!databaseExists()) { createDatabase(); } } /** * Returns true if database file exists, false otherwise. * @return */ private boolean databaseExists() { File dbFile = mContext.getDatabasePath(DATABASE_NAME); return dbFile.exists(); } /** * Creates database by copying it from assets directory. */ private void createDatabase() { String pairentPath = mContext.getDatabasePath(DATABASE_NAME).getPairent(); String path = mContext.getDatabasePath(DATABASE_NAME).getPath(); File file = new File(pairentPath); if (!file.exists()) { if (!file.mkdir()) { Log.w(TAG, "Unable to create database directory"); return; } } InputStream is = null; OutputStream os = null; try { is = mContext.getAssets().open(DATABASE_NAME); os = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(mContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putInt(SP_KEY_DB_VER, DATABASE_VERSION); editor.commit(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } 

    Depois de muita search. Eu achei que este database de pasta de ativos é somente leitura. você não pode atualizair o database na pasta de ativos. suponha que a sua próxima viewsão do aplicativo seja publicada no google play store com o novo database atualizado na pasta assert. se o nome do database em assert for o mesmo (no aplicativo anterior e no novo aplicativo), o sistema Android irá ler o file de database antigo. Por exemplo, o sistema de files não pode conter dois files com o mesmo nome. O que você precisa fazer é simplesmente alterair o nome do novo nome do file do database em dataOpenhelper.class. como database_1.db.

     public class DatabaseOpenHelper extends SQLiteAssetHelper { private static final String DATABASE_NAME = "dbbasic_5.db"; private static final int DATABASE_VERSION = 3; private Context contaxtDB; // ********* reminder ********** // only change database_name = like dbbasic_5.6.7.8 . // ******* do not change database_viewsion // public DatabaseOpenHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); contaxtDB = context; } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { super.onUpgrade(db, oldVersion, newVersion); } } } public class DatabaseOpenHelper extends SQLiteAssetHelper { private static final String DATABASE_NAME = "dbbasic_5.db"; private static final int DATABASE_VERSION = 3; private Context contaxtDB; // ********* reminder ********** // only change database_name = like dbbasic_5.6.7.8 . // ******* do not change database_viewsion // public DatabaseOpenHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); contaxtDB = context; } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { super.onUpgrade(db, oldVersion, newVersion); } } } public class DatabaseOpenHelper extends SQLiteAssetHelper { private static final String DATABASE_NAME = "dbbasic_5.db"; private static final int DATABASE_VERSION = 3; private Context contaxtDB; // ********* reminder ********** // only change database_name = like dbbasic_5.6.7.8 . // ******* do not change database_viewsion // public DatabaseOpenHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); contaxtDB = context; } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { super.onUpgrade(db, oldVersion, newVersion); } } 

    Este está funcionando bem, experimente

     public class DatabaseHelper extends SQLiteOpenHelper { private static final int DATABASE_VERSION = 3; private static final String SP_KEY_DB_VER = "db_view"; private static final String DATABASE_NAME = "db.db"; private static String DB_PATH = "/data/data/APP_PACKAGE/databases/"; static SQLiteDatabase db; public Context context; SessionManager session; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); this.context = context; session = SessionManager.getInstance(context);; //initialize(); } public void createDataBase() throws IOException { if (!checkDataBase()) { getWritableDatabase(); copyDataBase(); } } public boolean checkDataBase() { /**/ boolean found = new File(DB_PATH + DATABASE_NAME).exists(); if(found) { int dbVersion = Integer.valueOf(session.getData(SP_KEY_DB_VER, "1")); if (DATABASE_VERSION != dbVersion) { File dbFile = context.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w("Wairning: ", "Unable to update database"); } found = false; } } return found; } public void copyDataBase() throws IOException { InputStream myInput = this.context.getAssets().open(DATABASE_NAME); OutputStream myOutput = new FileOutputStream(DB_PATH + DATABASE_NAME); 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(); session.saveData(SP_KEY_DB_VER, String.valueOf(DATABASE_VERSION)); //int dbVersion = prefs.in(SP_KEY_DB_VER, 3); } public void openDataBase() throws SQLException { db = SQLiteDatabase.openDatabase(DB_PATH + DATABASE_NAME, null, 0); } } } public class DatabaseHelper extends SQLiteOpenHelper { private static final int DATABASE_VERSION = 3; private static final String SP_KEY_DB_VER = "db_view"; private static final String DATABASE_NAME = "db.db"; private static String DB_PATH = "/data/data/APP_PACKAGE/databases/"; static SQLiteDatabase db; public Context context; SessionManager session; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); this.context = context; session = SessionManager.getInstance(context);; //initialize(); } public void createDataBase() throws IOException { if (!checkDataBase()) { getWritableDatabase(); copyDataBase(); } } public boolean checkDataBase() { /**/ boolean found = new File(DB_PATH + DATABASE_NAME).exists(); if(found) { int dbVersion = Integer.valueOf(session.getData(SP_KEY_DB_VER, "1")); if (DATABASE_VERSION != dbVersion) { File dbFile = context.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w("Wairning: ", "Unable to update database"); } found = false; } } return found; } public void copyDataBase() throws IOException { InputStream myInput = this.context.getAssets().open(DATABASE_NAME); OutputStream myOutput = new FileOutputStream(DB_PATH + DATABASE_NAME); 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(); session.saveData(SP_KEY_DB_VER, String.valueOf(DATABASE_VERSION)); //int dbVersion = prefs.in(SP_KEY_DB_VER, 3); } public void openDataBase() throws SQLException { db = SQLiteDatabase.openDatabase(DB_PATH + DATABASE_NAME, null, 0); } } } public class DatabaseHelper extends SQLiteOpenHelper { private static final int DATABASE_VERSION = 3; private static final String SP_KEY_DB_VER = "db_view"; private static final String DATABASE_NAME = "db.db"; private static String DB_PATH = "/data/data/APP_PACKAGE/databases/"; static SQLiteDatabase db; public Context context; SessionManager session; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); this.context = context; session = SessionManager.getInstance(context);; //initialize(); } public void createDataBase() throws IOException { if (!checkDataBase()) { getWritableDatabase(); copyDataBase(); } } public boolean checkDataBase() { /**/ boolean found = new File(DB_PATH + DATABASE_NAME).exists(); if(found) { int dbVersion = Integer.valueOf(session.getData(SP_KEY_DB_VER, "1")); if (DATABASE_VERSION != dbVersion) { File dbFile = context.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w("Wairning: ", "Unable to update database"); } found = false; } } return found; } public void copyDataBase() throws IOException { InputStream myInput = this.context.getAssets().open(DATABASE_NAME); OutputStream myOutput = new FileOutputStream(DB_PATH + DATABASE_NAME); 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(); session.saveData(SP_KEY_DB_VER, String.valueOf(DATABASE_VERSION)); //int dbVersion = prefs.in(SP_KEY_DB_VER, 3); } public void openDataBase() throws SQLException { db = SQLiteDatabase.openDatabase(DB_PATH + DATABASE_NAME, null, 0); } } } public class DatabaseHelper extends SQLiteOpenHelper { private static final int DATABASE_VERSION = 3; private static final String SP_KEY_DB_VER = "db_view"; private static final String DATABASE_NAME = "db.db"; private static String DB_PATH = "/data/data/APP_PACKAGE/databases/"; static SQLiteDatabase db; public Context context; SessionManager session; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); this.context = context; session = SessionManager.getInstance(context);; //initialize(); } public void createDataBase() throws IOException { if (!checkDataBase()) { getWritableDatabase(); copyDataBase(); } } public boolean checkDataBase() { /**/ boolean found = new File(DB_PATH + DATABASE_NAME).exists(); if(found) { int dbVersion = Integer.valueOf(session.getData(SP_KEY_DB_VER, "1")); if (DATABASE_VERSION != dbVersion) { File dbFile = context.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w("Wairning: ", "Unable to update database"); } found = false; } } return found; } public void copyDataBase() throws IOException { InputStream myInput = this.context.getAssets().open(DATABASE_NAME); OutputStream myOutput = new FileOutputStream(DB_PATH + DATABASE_NAME); 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(); session.saveData(SP_KEY_DB_VER, String.valueOf(DATABASE_VERSION)); //int dbVersion = prefs.in(SP_KEY_DB_VER, 3); } public void openDataBase() throws SQLException { db = SQLiteDatabase.openDatabase(DB_PATH + DATABASE_NAME, null, 0); } } { public class DatabaseHelper extends SQLiteOpenHelper { private static final int DATABASE_VERSION = 3; private static final String SP_KEY_DB_VER = "db_view"; private static final String DATABASE_NAME = "db.db"; private static String DB_PATH = "/data/data/APP_PACKAGE/databases/"; static SQLiteDatabase db; public Context context; SessionManager session; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); this.context = context; session = SessionManager.getInstance(context);; //initialize(); } public void createDataBase() throws IOException { if (!checkDataBase()) { getWritableDatabase(); copyDataBase(); } } public boolean checkDataBase() { /**/ boolean found = new File(DB_PATH + DATABASE_NAME).exists(); if(found) { int dbVersion = Integer.valueOf(session.getData(SP_KEY_DB_VER, "1")); if (DATABASE_VERSION != dbVersion) { File dbFile = context.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w("Wairning: ", "Unable to update database"); } found = false; } } return found; } public void copyDataBase() throws IOException { InputStream myInput = this.context.getAssets().open(DATABASE_NAME); OutputStream myOutput = new FileOutputStream(DB_PATH + DATABASE_NAME); 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(); session.saveData(SP_KEY_DB_VER, String.valueOf(DATABASE_VERSION)); //int dbVersion = prefs.in(SP_KEY_DB_VER, 3); } public void openDataBase() throws SQLException { db = SQLiteDatabase.openDatabase(DB_PATH + DATABASE_NAME, null, 0); } } } public class DatabaseHelper extends SQLiteOpenHelper { private static final int DATABASE_VERSION = 3; private static final String SP_KEY_DB_VER = "db_view"; private static final String DATABASE_NAME = "db.db"; private static String DB_PATH = "/data/data/APP_PACKAGE/databases/"; static SQLiteDatabase db; public Context context; SessionManager session; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); this.context = context; session = SessionManager.getInstance(context);; //initialize(); } public void createDataBase() throws IOException { if (!checkDataBase()) { getWritableDatabase(); copyDataBase(); } } public boolean checkDataBase() { /**/ boolean found = new File(DB_PATH + DATABASE_NAME).exists(); if(found) { int dbVersion = Integer.valueOf(session.getData(SP_KEY_DB_VER, "1")); if (DATABASE_VERSION != dbVersion) { File dbFile = context.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w("Wairning: ", "Unable to update database"); } found = false; } } return found; } public void copyDataBase() throws IOException { InputStream myInput = this.context.getAssets().open(DATABASE_NAME); OutputStream myOutput = new FileOutputStream(DB_PATH + DATABASE_NAME); 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(); session.saveData(SP_KEY_DB_VER, String.valueOf(DATABASE_VERSION)); //int dbVersion = prefs.in(SP_KEY_DB_VER, 3); } public void openDataBase() throws SQLException { db = SQLiteDatabase.openDatabase(DB_PATH + DATABASE_NAME, null, 0); } } } public class DatabaseHelper extends SQLiteOpenHelper { private static final int DATABASE_VERSION = 3; private static final String SP_KEY_DB_VER = "db_view"; private static final String DATABASE_NAME = "db.db"; private static String DB_PATH = "/data/data/APP_PACKAGE/databases/"; static SQLiteDatabase db; public Context context; SessionManager session; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); this.context = context; session = SessionManager.getInstance(context);; //initialize(); } public void createDataBase() throws IOException { if (!checkDataBase()) { getWritableDatabase(); copyDataBase(); } } public boolean checkDataBase() { /**/ boolean found = new File(DB_PATH + DATABASE_NAME).exists(); if(found) { int dbVersion = Integer.valueOf(session.getData(SP_KEY_DB_VER, "1")); if (DATABASE_VERSION != dbVersion) { File dbFile = context.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w("Wairning: ", "Unable to update database"); } found = false; } } return found; } public void copyDataBase() throws IOException { InputStream myInput = this.context.getAssets().open(DATABASE_NAME); OutputStream myOutput = new FileOutputStream(DB_PATH + DATABASE_NAME); 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(); session.saveData(SP_KEY_DB_VER, String.valueOf(DATABASE_VERSION)); //int dbVersion = prefs.in(SP_KEY_DB_VER, 3); } public void openDataBase() throws SQLException { db = SQLiteDatabase.openDatabase(DB_PATH + DATABASE_NAME, null, 0); } } } public class DatabaseHelper extends SQLiteOpenHelper { private static final int DATABASE_VERSION = 3; private static final String SP_KEY_DB_VER = "db_view"; private static final String DATABASE_NAME = "db.db"; private static String DB_PATH = "/data/data/APP_PACKAGE/databases/"; static SQLiteDatabase db; public Context context; SessionManager session; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); this.context = context; session = SessionManager.getInstance(context);; //initialize(); } public void createDataBase() throws IOException { if (!checkDataBase()) { getWritableDatabase(); copyDataBase(); } } public boolean checkDataBase() { /**/ boolean found = new File(DB_PATH + DATABASE_NAME).exists(); if(found) { int dbVersion = Integer.valueOf(session.getData(SP_KEY_DB_VER, "1")); if (DATABASE_VERSION != dbVersion) { File dbFile = context.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w("Wairning: ", "Unable to update database"); } found = false; } } return found; } public void copyDataBase() throws IOException { InputStream myInput = this.context.getAssets().open(DATABASE_NAME); OutputStream myOutput = new FileOutputStream(DB_PATH + DATABASE_NAME); 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(); session.saveData(SP_KEY_DB_VER, String.valueOf(DATABASE_VERSION)); //int dbVersion = prefs.in(SP_KEY_DB_VER, 3); } public void openDataBase() throws SQLException { db = SQLiteDatabase.openDatabase(DB_PATH + DATABASE_NAME, null, 0); } } } public class DatabaseHelper extends SQLiteOpenHelper { private static final int DATABASE_VERSION = 3; private static final String SP_KEY_DB_VER = "db_view"; private static final String DATABASE_NAME = "db.db"; private static String DB_PATH = "/data/data/APP_PACKAGE/databases/"; static SQLiteDatabase db; public Context context; SessionManager session; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); this.context = context; session = SessionManager.getInstance(context);; //initialize(); } public void createDataBase() throws IOException { if (!checkDataBase()) { getWritableDatabase(); copyDataBase(); } } public boolean checkDataBase() { /**/ boolean found = new File(DB_PATH + DATABASE_NAME).exists(); if(found) { int dbVersion = Integer.valueOf(session.getData(SP_KEY_DB_VER, "1")); if (DATABASE_VERSION != dbVersion) { File dbFile = context.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w("Wairning: ", "Unable to update database"); } found = false; } } return found; } public void copyDataBase() throws IOException { InputStream myInput = this.context.getAssets().open(DATABASE_NAME); OutputStream myOutput = new FileOutputStream(DB_PATH + DATABASE_NAME); 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(); session.saveData(SP_KEY_DB_VER, String.valueOf(DATABASE_VERSION)); //int dbVersion = prefs.in(SP_KEY_DB_VER, 3); } public void openDataBase() throws SQLException { db = SQLiteDatabase.openDatabase(DB_PATH + DATABASE_NAME, null, 0); } } comprimento int; public class DatabaseHelper extends SQLiteOpenHelper { private static final int DATABASE_VERSION = 3; private static final String SP_KEY_DB_VER = "db_view"; private static final String DATABASE_NAME = "db.db"; private static String DB_PATH = "/data/data/APP_PACKAGE/databases/"; static SQLiteDatabase db; public Context context; SessionManager session; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); this.context = context; session = SessionManager.getInstance(context);; //initialize(); } public void createDataBase() throws IOException { if (!checkDataBase()) { getWritableDatabase(); copyDataBase(); } } public boolean checkDataBase() { /**/ boolean found = new File(DB_PATH + DATABASE_NAME).exists(); if(found) { int dbVersion = Integer.valueOf(session.getData(SP_KEY_DB_VER, "1")); if (DATABASE_VERSION != dbVersion) { File dbFile = context.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w("Wairning: ", "Unable to update database"); } found = false; } } return found; } public void copyDataBase() throws IOException { InputStream myInput = this.context.getAssets().open(DATABASE_NAME); OutputStream myOutput = new FileOutputStream(DB_PATH + DATABASE_NAME); 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(); session.saveData(SP_KEY_DB_VER, String.valueOf(DATABASE_VERSION)); //int dbVersion = prefs.in(SP_KEY_DB_VER, 3); } public void openDataBase() throws SQLException { db = SQLiteDatabase.openDatabase(DB_PATH + DATABASE_NAME, null, 0); } } } public class DatabaseHelper extends SQLiteOpenHelper { private static final int DATABASE_VERSION = 3; private static final String SP_KEY_DB_VER = "db_view"; private static final String DATABASE_NAME = "db.db"; private static String DB_PATH = "/data/data/APP_PACKAGE/databases/"; static SQLiteDatabase db; public Context context; SessionManager session; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); this.context = context; session = SessionManager.getInstance(context);; //initialize(); } public void createDataBase() throws IOException { if (!checkDataBase()) { getWritableDatabase(); copyDataBase(); } } public boolean checkDataBase() { /**/ boolean found = new File(DB_PATH + DATABASE_NAME).exists(); if(found) { int dbVersion = Integer.valueOf(session.getData(SP_KEY_DB_VER, "1")); if (DATABASE_VERSION != dbVersion) { File dbFile = context.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w("Wairning: ", "Unable to update database"); } found = false; } } return found; } public void copyDataBase() throws IOException { InputStream myInput = this.context.getAssets().open(DATABASE_NAME); OutputStream myOutput = new FileOutputStream(DB_PATH + DATABASE_NAME); 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(); session.saveData(SP_KEY_DB_VER, String.valueOf(DATABASE_VERSION)); //int dbVersion = prefs.in(SP_KEY_DB_VER, 3); } public void openDataBase() throws SQLException { db = SQLiteDatabase.openDatabase(DB_PATH + DATABASE_NAME, null, 0); } } } public class DatabaseHelper extends SQLiteOpenHelper { private static final int DATABASE_VERSION = 3; private static final String SP_KEY_DB_VER = "db_view"; private static final String DATABASE_NAME = "db.db"; private static String DB_PATH = "/data/data/APP_PACKAGE/databases/"; static SQLiteDatabase db; public Context context; SessionManager session; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); this.context = context; session = SessionManager.getInstance(context);; //initialize(); } public void createDataBase() throws IOException { if (!checkDataBase()) { getWritableDatabase(); copyDataBase(); } } public boolean checkDataBase() { /**/ boolean found = new File(DB_PATH + DATABASE_NAME).exists(); if(found) { int dbVersion = Integer.valueOf(session.getData(SP_KEY_DB_VER, "1")); if (DATABASE_VERSION != dbVersion) { File dbFile = context.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w("Wairning: ", "Unable to update database"); } found = false; } } return found; } public void copyDataBase() throws IOException { InputStream myInput = this.context.getAssets().open(DATABASE_NAME); OutputStream myOutput = new FileOutputStream(DB_PATH + DATABASE_NAME); 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(); session.saveData(SP_KEY_DB_VER, String.valueOf(DATABASE_VERSION)); //int dbVersion = prefs.in(SP_KEY_DB_VER, 3); } public void openDataBase() throws SQLException { db = SQLiteDatabase.openDatabase(DB_PATH + DATABASE_NAME, null, 0); } } } public class DatabaseHelper extends SQLiteOpenHelper { private static final int DATABASE_VERSION = 3; private static final String SP_KEY_DB_VER = "db_view"; private static final String DATABASE_NAME = "db.db"; private static String DB_PATH = "/data/data/APP_PACKAGE/databases/"; static SQLiteDatabase db; public Context context; SessionManager session; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); this.context = context; session = SessionManager.getInstance(context);; //initialize(); } public void createDataBase() throws IOException { if (!checkDataBase()) { getWritableDatabase(); copyDataBase(); } } public boolean checkDataBase() { /**/ boolean found = new File(DB_PATH + DATABASE_NAME).exists(); if(found) { int dbVersion = Integer.valueOf(session.getData(SP_KEY_DB_VER, "1")); if (DATABASE_VERSION != dbVersion) { File dbFile = context.getDatabasePath(DATABASE_NAME); if (!dbFile.delete()) { Log.w("Wairning: ", "Unable to update database"); } found = false; } } return found; } public void copyDataBase() throws IOException { InputStream myInput = this.context.getAssets().open(DATABASE_NAME); OutputStream myOutput = new FileOutputStream(DB_PATH + DATABASE_NAME); 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(); session.saveData(SP_KEY_DB_VER, String.valueOf(DATABASE_VERSION)); //int dbVersion = prefs.in(SP_KEY_DB_VER, 3); } public void openDataBase() throws SQLException { db = SQLiteDatabase.openDatabase(DB_PATH + DATABASE_NAME, null, 0); } } 

    MainActivity -> OnCreate

     db = new DatabaseHelper(context); try { db.createDataBase(); } catch (IOException ioe) { throw new Error("Unable to create database"); } db.openDataBase(); } catch (IOException ioe) { db = new DatabaseHelper(context); try { db.createDataBase(); } catch (IOException ioe) { throw new Error("Unable to create database"); } db.openDataBase(); } db = new DatabaseHelper(context); try { db.createDataBase(); } catch (IOException ioe) { throw new Error("Unable to create database"); } db.openDataBase(); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.