I have been thoroughly researching on this and all the examples I found and tested did not work. To leave the code more organized I would like to do this using the OpenHelper class but I have already tested the openOrCreate () method on both OpenHelper and Activity itself. Here is my code:
public class CriaBancoApp extends SQLiteOpenHelper {
private static final String NOME_BANCO = "BD_AppNome.db";
private static final String CAMINHO_BANCO = Environment.getExternalStorageDirectory() + "/AppNome/Databases/";
private static final int VERSAO = 1;
public CriaBancoApp(Context contexto) {
super(contexto, CAMINHO_BANCO, null, VERSAO);
//SQLiteDatabase.openOrCreateDatabase(CAMINHO_BANCO, null);
}
@Override
public void onCreate(SQLiteDatabase db) {
String sql = "CREATE TABLE NomeTabela ("
+ "Id INTEGER PRIMARY KEY AUTOINCREMENT,"
+ "AutorTraducao TEXT)";
db.execSQL(sql);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS NomeTabela");
onCreate(db);
}
}
Then I create the instance in MainActivity:
CriaBancoApp banco = new CriaBancoApp(this);
And when starting the app date. Regarding the path the app folders are created before creating the database I even commented this line to check if the folders are created and are. The xml Manifest already has write permission that automatically includes the read permission.