Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export functionality using file dialog #158

Open
Jogi04 opened this issue Aug 10, 2022 · 9 comments
Open

Export functionality using file dialog #158

Jogi04 opened this issue Aug 10, 2022 · 9 comments
Labels
enhancement New feature or request

Comments

@Jogi04
Copy link

Jogi04 commented Aug 10, 2022

Hi,

I really like the simplicity and the look and feel of the app.
But I miss the feature to export the events using a file dialog so that you can save the backup file wherever you want. On my device (Samsung A71, Android 12) I'm unable to locate the backup file in Android/data/com.minar.birday/files since the folder com.minar.birday doesn't exist in Android/data.

Thank you very much for your dedication to this awesome project!

@Dilshan-H
Copy link

@jogi123 Actually it's the normal behavior; after Android 11 update, preloaded My Files app doesn't show files and folders within 'android/data'. (due to access permissions)
As a workaround, you can use a third party file manager to access the location and copy the files into anywhere you want.

I agree with you - If we can save the export file in a specific location it would be great though...

@m-i-n-a-r
Copy link
Owner

When i wrote the export function, i wasn't able to provide such feature, but i agree that it could be useful and more user friendly. I'll see what i can do ;)

@m-i-n-a-r m-i-n-a-r added the enhancement New feature or request label Aug 19, 2022
@Jogi04
Copy link
Author

Jogi04 commented Aug 20, 2022

@Dilshan-H Sorry, my bad. Thanks for the advice!
@m-i-n-a-r Thank you for your quick answer!

@DominikNovosel
Copy link
Contributor

DominikNovosel commented Nov 13, 2022

I also use a Samsung phone and cannot access the data folder with the default file manager. However, when you export the backup, a share dialog should pop up. The options will vary based on the device and the apps you use, but it may even have an option to save the file wherever you want. Mine, of course, doesn't. So the easiest solution for me personally is to send the file to my computer using KDE Connect and back to my phone so it ends up in my Downloads folder, which is accessible using conventional means.

Is it ideal? Nope.
Will most people find it practical to do the same? Nope.
Can it be fixed in the app? Super nope. This up to Android and Samsung to fix.

@m-i-n-a-r
Copy link
Owner

Yep, i agree. I always tend let the OS work instead of writing features in the app from scratch (and that's what Goole suggest normally, since Android is becoming really restrictive regarding privacy, see the need to ask for a permission to send notifications 😵‍💫 ). This means that to avoid asking additional permissions and follow the scoped storage principle, the backup is saved in that folder and shared afterwards. Same story for the app language (selectable from settings in Android 13+), the notification sound, the battery optimization disabling process and the file selection. Another very important fact to consider is that, if i add a new feature, i have to translate it in a A LOT of languages, or wait for the translators. That's why i added an "experimental settings" section in v4.x.x: it contains advanced, experimental and untranslated settings!

@victorbnl
Copy link

Why not just replicate the behaviour of the default “Contacts” application, in which a dialog is shown the user to ask which file to back up the data in? It should be cleanly feasible even with Android 11+ file permission system, right?

@victorbnl
Copy link

victorbnl commented Aug 31, 2023

Here is a draft I came up with by looking at other projects.

val launcher = (context as MainActivity).registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
    val intent = result.data
    val uri = intent?.data
    uri?.let { uri ->
        fileFullPath = uri.path ?: ""
        context.contentResolver.openOutputStream(uri)?.use { outputStream ->
            outputStream.write(dbFile.readBytes())
            (context as MainActivity).runOnUiThread {
                context.showSnackbar(context.getString(R.string.birday_export_success))
            }
        } ?: run {
            (context as MainActivity).runOnUiThread {
                context.showSnackbar(context.getString(R.string.birday_export_failure))
            }
        }
    }
}

val intent = Intent(Intent.ACTION_CREATE_DOCUMENT)
    .addCategory(Intent.CATEGORY_OPENABLE)
    .setType("application/octet-stream")
    .putExtra(Intent.EXTRA_TITLE, fileName)
    
launcher.launch(intent)

I can’t implement it myself because I’m not a Kotlin developer and I don’t have a good grasp of Android features such as Lifecycles (I tried to put the code above in BirdayExporter.exportEvents but it didn’t work because MainActivity.registerForActivityResult should be called before the state is STARTED). Plus, I don’t even completely understand the code I have written above, it is mostly copy-pasted snippets put together. But here is what I think it would look like in broad strokes.

@m-i-n-a-r
Copy link
Owner

m-i-n-a-r commented Oct 17, 2023

Hi and sorry for the super late reply. I'll take a look as soon as I have some free time, thanks!

@victorbnl
Copy link

Don’t worry, take your time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants