Created
May 8, 2020 18:11
-
-
Save varundwarkani/401cb237959283755d8f91ff69d0b55a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
super.onActivityResult(requestCode, resultCode, data); | |
if (requestCode == 12 && resultCode == RESULT_OK && data != null) { | |
Uri fileUri = data.getData(); | |
try { | |
assert fileUri != null; | |
InputStream inputStream = getContentResolver().openInputStream(fileUri); | |
if (validFile(fileUri)) { | |
restoreDatabase(inputStream); | |
} else { | |
Utils.showSnackbar(findViewById(android.R.id.content), getString(R.string.restore_failed), 1); | |
} | |
if (inputStream != null) { | |
inputStream.close(); | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
What makes the getFilePath(context, 0) ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello ,
Thanks for the share such a good solutions.
I have a question. I also implemented the file chooser like you and onActivityResult.
here you can see .
My problem is on the Input stream when I select the file from chooser.
When input stream is create with the fileUri path is always null. That is why I can not restore my backed up database.
inputstream;
fileUri;
Could you please help me ? By the way I did not used your backup method I have another one. But nearly the same.