Hello! I'm also starting out with Kotlin (and Andr...
# getting-started
m
Hello! I'm also starting out with Kotlin (and Android). Is there a nicer (more idiomatic) way of doing the following check than the following?
a
hi! You should join #android as well πŸ™‚
Environment.getExternalStorageDirectory()
is deprecated as outlined here, you shouldn't use it: https://developer.android.com/reference/kotlin/android/os/Environment?hl=en#getExternalStorageDirectory()
m
Aha, cool!
Shoudln't I get a warning in Android studio?
I'm in #android as well, wasn't sure where to ask the question.
a
yes, though you need to be building against the latest Android SDK where it's marked as such. compileSdkVersion should always be the latest public SDK, minSdkVersion should always be the oldest version you'd like to support, and targetSdkVersion is the "quirks mode" level you're requesting from Android at runtime. (Which ideally should also always be the latest.)
m
Ah, that makes sense. I'm building against KitKat 4.4
a
don't do that πŸ™‚
m
or minSdkVersion is that
a
you can still set minSdkVersion=19 when building against the latest
m
Im building 7.0 and 9.0
Actually, I might not be πŸ˜„ I don't know the settings very well. I have 7.0 and 9.0 SDKs
a
I realize this is a lot to take in for someone new to both Kotlin and Android, but the scoped storage changes for Q are pretty significant: https://developer.android.com/preview/privacy/scoped-storage
m
Ok! I hope the files Im looking for are external πŸ™‚
Thank you for your help!
a
well, since you're looking for a directory that I assume is meant to be private to/specific to your app, you might want to start with https://developer.android.com/reference/android/content/Context#getFilesDir() instead of messing with external storage at all
and if you're looking for a directory that was created by/belongs to an app other than your own, Android Q is going to make that deliberately harder for you to do πŸ™‚
m
Hehe πŸ™‚ Makes sense, from a security perspective
of course, harder for a developer πŸ™‚
a
Better for users though!
m
Yes, indeed
If I have the github repo, can I find where they could be located?
File(Environment.getExternalStorageDirectory(), "AnkiDroid").getAbsolutePath(); This is how they use it themselves
a
they're likely to run into problems themselves too
m
Ok, Ill see what I can do
this is app is mainly for myself anyway
a
in any case, the spirit of the changes in Q isn't to restrict what users can do in terms of letting apps open files from other apps, it's to restrict apps being able to do it silently without the user initiating it. If you go through the system file pickers to let the user grant your app access to a specific external storage directory, you can still do it, but a lot of the stackoverflow wisdom out on the web right now is going to be very outdated soon
the biggest criticism from developers around this is usually that the user experience is scary/unknown when an app opens a file picker to grant access, and it's kinda meant to be. But if this app is for your own use that's not really a concern πŸ™‚
m
Yeah, looking into Kotlin in general, I find a lot of old information
Early 2011
or even older Java stuff πŸ˜„
Ill read the references you sent
a
our Android docs have a lot of cruft right now too, there are some ongoing projects to improve it. Especially some of the kotlin snippets that were added as translations of java code examples are...not ideal πŸ™‚
m
I managed to load the resource and play it! I don't think the solution is future proof, but it will do for now. Thanks a lot!
πŸ‘ 1