creating a SQLite Backup on root of SD card
How can I backup my SQLiteDatabase
on the root of my SD card instead of com.jti.mikee.jti_pos
. because the problem that I've encountering right now is when i uninstall the app. the package name on SD Card was removed. even the sql backups. I'm developing on a device android 4.4
This is my code for back up a database:
private void DBBackup() {
try {
File sd = getContext().getExternalFilesDirs(null);
File data = Environment.getDataDirectory();
if (sd[1].canWrite()) {
String currentDBPath = "/data/com.jti.mikee.jti_pos/databases/" + DBHelper.DB_NAME;
String backupDBPath =DBHelper.DB_NAME;
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd[1], backupDBPath);
if (currentDB.exists()) {
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
}
}
} catch (Throwable e) {
e.printStackTrace();
}
}
android sqlite
add a comment |
How can I backup my SQLiteDatabase
on the root of my SD card instead of com.jti.mikee.jti_pos
. because the problem that I've encountering right now is when i uninstall the app. the package name on SD Card was removed. even the sql backups. I'm developing on a device android 4.4
This is my code for back up a database:
private void DBBackup() {
try {
File sd = getContext().getExternalFilesDirs(null);
File data = Environment.getDataDirectory();
if (sd[1].canWrite()) {
String currentDBPath = "/data/com.jti.mikee.jti_pos/databases/" + DBHelper.DB_NAME;
String backupDBPath =DBHelper.DB_NAME;
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd[1], backupDBPath);
if (currentDB.exists()) {
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
}
}
} catch (Throwable e) {
e.printStackTrace();
}
}
android sqlite
Of course that apps private folder will get removed, if the app is deinstalled. That is the point of deinstalling it. You certainly can copy any files you like to the sdcard, but they will be visible and everyone can tamper with those files in the public space. You can use normal file handling functions as offered by android/java for that, this works just fine.
– arkascha
Nov 21 at 6:05
add a comment |
How can I backup my SQLiteDatabase
on the root of my SD card instead of com.jti.mikee.jti_pos
. because the problem that I've encountering right now is when i uninstall the app. the package name on SD Card was removed. even the sql backups. I'm developing on a device android 4.4
This is my code for back up a database:
private void DBBackup() {
try {
File sd = getContext().getExternalFilesDirs(null);
File data = Environment.getDataDirectory();
if (sd[1].canWrite()) {
String currentDBPath = "/data/com.jti.mikee.jti_pos/databases/" + DBHelper.DB_NAME;
String backupDBPath =DBHelper.DB_NAME;
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd[1], backupDBPath);
if (currentDB.exists()) {
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
}
}
} catch (Throwable e) {
e.printStackTrace();
}
}
android sqlite
How can I backup my SQLiteDatabase
on the root of my SD card instead of com.jti.mikee.jti_pos
. because the problem that I've encountering right now is when i uninstall the app. the package name on SD Card was removed. even the sql backups. I'm developing on a device android 4.4
This is my code for back up a database:
private void DBBackup() {
try {
File sd = getContext().getExternalFilesDirs(null);
File data = Environment.getDataDirectory();
if (sd[1].canWrite()) {
String currentDBPath = "/data/com.jti.mikee.jti_pos/databases/" + DBHelper.DB_NAME;
String backupDBPath =DBHelper.DB_NAME;
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd[1], backupDBPath);
if (currentDB.exists()) {
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
}
}
} catch (Throwable e) {
e.printStackTrace();
}
}
android sqlite
android sqlite
asked Nov 21 at 5:58
Mike Gorospe
14914
14914
Of course that apps private folder will get removed, if the app is deinstalled. That is the point of deinstalling it. You certainly can copy any files you like to the sdcard, but they will be visible and everyone can tamper with those files in the public space. You can use normal file handling functions as offered by android/java for that, this works just fine.
– arkascha
Nov 21 at 6:05
add a comment |
Of course that apps private folder will get removed, if the app is deinstalled. That is the point of deinstalling it. You certainly can copy any files you like to the sdcard, but they will be visible and everyone can tamper with those files in the public space. You can use normal file handling functions as offered by android/java for that, this works just fine.
– arkascha
Nov 21 at 6:05
Of course that apps private folder will get removed, if the app is deinstalled. That is the point of deinstalling it. You certainly can copy any files you like to the sdcard, but they will be visible and everyone can tamper with those files in the public space. You can use normal file handling functions as offered by android/java for that, this works just fine.
– arkascha
Nov 21 at 6:05
Of course that apps private folder will get removed, if the app is deinstalled. That is the point of deinstalling it. You certainly can copy any files you like to the sdcard, but they will be visible and everyone can tamper with those files in the public space. You can use normal file handling functions as offered by android/java for that, this works just fine.
– arkascha
Nov 21 at 6:05
add a comment |
2 Answers
2
active
oldest
votes
getContext().getExternalFilesDirs(null) returns somewhere on the SD card but still belongs to the application.
You should use Environment.getExternalStorageDirectory().
I have tried this but there is no back up created
– Mike Gorospe
Nov 21 at 6:19
add a comment |
this should return the internal storage at [0]
and the external storage at [1]
:
File paths = ContextCompat.getExternalFilesDirs(getContext(), null);
alternatively ...
File sdcard = Environment.getExternalStorageDirectory();
String path = sdcard.getAbsolutePath();
the .getAbsolutePath()
might be the trick here - for both methods of obtaining the handle.
I'm testing this now. thanks
– Mike Gorospe
Nov 21 at 6:22
as of now its not working. how can I create an public folder for it?
– Mike Gorospe
Dec 4 at 6:06
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406059%2fcreating-a-sqlite-backup-on-root-of-sd-card%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
getContext().getExternalFilesDirs(null) returns somewhere on the SD card but still belongs to the application.
You should use Environment.getExternalStorageDirectory().
I have tried this but there is no back up created
– Mike Gorospe
Nov 21 at 6:19
add a comment |
getContext().getExternalFilesDirs(null) returns somewhere on the SD card but still belongs to the application.
You should use Environment.getExternalStorageDirectory().
I have tried this but there is no back up created
– Mike Gorospe
Nov 21 at 6:19
add a comment |
getContext().getExternalFilesDirs(null) returns somewhere on the SD card but still belongs to the application.
You should use Environment.getExternalStorageDirectory().
getContext().getExternalFilesDirs(null) returns somewhere on the SD card but still belongs to the application.
You should use Environment.getExternalStorageDirectory().
answered Nov 21 at 6:05
AIMIN PAN
20628
20628
I have tried this but there is no back up created
– Mike Gorospe
Nov 21 at 6:19
add a comment |
I have tried this but there is no back up created
– Mike Gorospe
Nov 21 at 6:19
I have tried this but there is no back up created
– Mike Gorospe
Nov 21 at 6:19
I have tried this but there is no back up created
– Mike Gorospe
Nov 21 at 6:19
add a comment |
this should return the internal storage at [0]
and the external storage at [1]
:
File paths = ContextCompat.getExternalFilesDirs(getContext(), null);
alternatively ...
File sdcard = Environment.getExternalStorageDirectory();
String path = sdcard.getAbsolutePath();
the .getAbsolutePath()
might be the trick here - for both methods of obtaining the handle.
I'm testing this now. thanks
– Mike Gorospe
Nov 21 at 6:22
as of now its not working. how can I create an public folder for it?
– Mike Gorospe
Dec 4 at 6:06
add a comment |
this should return the internal storage at [0]
and the external storage at [1]
:
File paths = ContextCompat.getExternalFilesDirs(getContext(), null);
alternatively ...
File sdcard = Environment.getExternalStorageDirectory();
String path = sdcard.getAbsolutePath();
the .getAbsolutePath()
might be the trick here - for both methods of obtaining the handle.
I'm testing this now. thanks
– Mike Gorospe
Nov 21 at 6:22
as of now its not working. how can I create an public folder for it?
– Mike Gorospe
Dec 4 at 6:06
add a comment |
this should return the internal storage at [0]
and the external storage at [1]
:
File paths = ContextCompat.getExternalFilesDirs(getContext(), null);
alternatively ...
File sdcard = Environment.getExternalStorageDirectory();
String path = sdcard.getAbsolutePath();
the .getAbsolutePath()
might be the trick here - for both methods of obtaining the handle.
this should return the internal storage at [0]
and the external storage at [1]
:
File paths = ContextCompat.getExternalFilesDirs(getContext(), null);
alternatively ...
File sdcard = Environment.getExternalStorageDirectory();
String path = sdcard.getAbsolutePath();
the .getAbsolutePath()
might be the trick here - for both methods of obtaining the handle.
edited Nov 21 at 6:11
answered Nov 21 at 6:06
Martin Zeitler
14.2k33863
14.2k33863
I'm testing this now. thanks
– Mike Gorospe
Nov 21 at 6:22
as of now its not working. how can I create an public folder for it?
– Mike Gorospe
Dec 4 at 6:06
add a comment |
I'm testing this now. thanks
– Mike Gorospe
Nov 21 at 6:22
as of now its not working. how can I create an public folder for it?
– Mike Gorospe
Dec 4 at 6:06
I'm testing this now. thanks
– Mike Gorospe
Nov 21 at 6:22
I'm testing this now. thanks
– Mike Gorospe
Nov 21 at 6:22
as of now its not working. how can I create an public folder for it?
– Mike Gorospe
Dec 4 at 6:06
as of now its not working. how can I create an public folder for it?
– Mike Gorospe
Dec 4 at 6:06
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406059%2fcreating-a-sqlite-backup-on-root-of-sd-card%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Of course that apps private folder will get removed, if the app is deinstalled. That is the point of deinstalling it. You certainly can copy any files you like to the sdcard, but they will be visible and everyone can tamper with those files in the public space. You can use normal file handling functions as offered by android/java for that, this works just fine.
– arkascha
Nov 21 at 6:05