Open alorma opened 1 month ago
Hi @alorma ! Thank you for your kind words!
I tried to use Android App Startup to initialize the library under the hood, but I wasn't successful.
To access files on Android, we need to get a result from an activity. This can be done using:
ComponentActivity.registerForActivityResult(...)
ComponentActivity.activityResultRegistry.register(...)
I couldn't find a way to avoid using Activity or ComponentActivity in the process. When using App Startup, the context available isn't linked to any activity, and I couldn't figure out how to obtain the activity from the Android App Startup Initializer.
As a result, I created the FileKit.init(activity: ComponentActivity)
method 🥲
If you have any idea on how to solve this problem and remove this method, I'd love to hear them!
Oh, my bad then. I thought that was supposed to be done on the Application not the Activity.
I could think on how to do that for compose. But no for regular Android view system
I mean.
On compose we have rememberLauncherForActivityResult()
right?
That's a @Composable
method that has access to LocalContext
, and it can be cast to ComponentActivity
(safely with an as?
... So you will have the right activity then?
Maybe creating your own rememberLauncherForActivityResult()
?
Sorry for the late response.
Yeah you're right, on compose we have access to all the information that we need from the @Composable
. FileKit compose methods (like rememberFilePickerLauncher) are working without any initialization, even on Android.
I need to improve the documentation on that point:
FileKit.pick()
requires calling FileKit.init(this)
for AndroidrememberFilePickerLauncher()
are working without any setupThe ideal is to find a way to remove this initialization setup and get the current ComponentActivity without any developer action. Android App Startup seems to be the solution, but I'm probably missing something to make it work.
Hi! Thanks for the libray it's great to see more and more features coming to KMP and Compose Multiplaform!
I saw that the library requests initialization on Android, and thought about using
ContentProvider
for it.Do you ever read about that? Libraries like firebase do it by themselves.
Here's a blog post that talks about that: https://medium.com/turkcell/using-android-content-providers-for-automatically-initialization-a5d3c05efd4e
Thanks anyway!