0
I have researched this thoroughly and all the examples I have found and tested have not worked. To make the code more organized I would like to do this using the Openhelper class but I have already tested the openOrCreate () method both in Openhelper and in Activity itself. Below follows 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 closes. Regarding the path the folders of the app 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 which automatically includes read permission.