Witam, prosiłbym o pomoc bo bardzo mi na tym zależy, wydałem projekt na sklep play, chciałem sprawdzić czy wszystko działa tak jak w normalnej wersji i okazuje się że nie działa moja funkcja importowania/exportowania bazy danych. Była to operacja na plikach przez File.copy() oraz przenoszenie i usuwanie bazy danych z SQLite.
Gdy wszedłem w aplikację z poziomu android studio odnajduję przyczynę tego zdarzenia Package "pl.xezolpl.mylibrary" is not debuggable. Znalazłem w internecie, że mogę dać do manifestu android:debuggable="true"
i tak też teraz ustawiłem. Tylko że w takim wypadku tworząc aplikację jako bundle do wstawienia na sklep play powinienem dawać normalnie release
czy debug
żeby to mogło działać? Czy na wersji debug
nie będzie mi to wiele wolniej chodziło?
Pozdrawiam, niżej kod od funkcji importu w razie jakby miał on jakieś znaczenie.
public boolean importDatabaseFile(File importedFile) throws IOException {
boolean result = false;
if (!checkBackupDir()) {
return false;
}
//Check the database exists
if (!dbOriginal.exists()) {
return false;
}
if (!importedFile.getName().contains(".db")){
return false;
}
if (importedFile.getAbsolutePath().substring(0, 5).contains("/root")) {
importedFile = new File(importedFile.getAbsolutePath().substring(5));
}
File dbBackup = createBackupFile();
try {
FileChannel sourceChannel = new FileInputStream(dbOriginal).getChannel();
FileChannel destChannel = new FileOutputStream(dbBackup).getChannel();
//Transfer original to the copy -> if transferredBytes>0 then successfully transferred
if (sourceChannel.transferTo(0, sourceChannel.size(), destChannel) > 0) {
sourceChannel.close();
destChannel.close();
//Now let's transfer importedFile to the original database's place
FileChannel importChannel = new FileInputStream(importedFile).getChannel();
FileChannel destinationChannel = new FileOutputStream(dbOriginal).getChannel();
//if transferredBytes>0 again then we successfully imported the database file
LibraryDatabase.getDatabase(context.getApplicationContext()).close();
if (importChannel.transferTo(0, importChannel.size(), destinationChannel) > 0) {
result = true;
}
importChannel.close();
destinationChannel.close();
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
return result;
}
public boolean exportDatabaseFile(File exportFile) {
String fileName = "library_database-" + time + ".db";
String dirPath = (Environment.getExternalStorageDirectory().getPath() +
exportFile.getParentFile()).replace("document/primary:", "");
String absoluteFilePath = dirPath + "/" + fileName;
new File(dirPath + "/" + exportFile.getName()).delete();
File dbCopy = new File(absoluteFilePath);
boolean result = false;
try {
if (!dbCopy.exists()) {
if (!dbCopy.createNewFile()) {
return false;
}
}
FileChannel sourceChannel = new FileInputStream(dbOriginal).getChannel();
FileChannel destChannel = new FileOutputStream(dbCopy).getChannel();
if (sourceChannel.transferTo(0, sourceChannel.size(), destChannel) > 0) {
result = true;
}
sourceChannel.close();
destChannel.close();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}