pawegio / KAndroid

Kotlin library for Android
Apache License 2.0
896 stars 81 forks source link

`Environment.isExternalStorageWritable` not usable #53

Open jasonsparc opened 6 years ago

jasonsparc commented 6 years ago

The extension functions for android.os.Environment that is currently provided by KEnvironment.kt cannot be used without first creating an instance of Environment which isn't desirable because android.os.Environment is just meant as a utility class filled with static methods.

To access the provided extension functions I have to write this:

if (Environment().isExternalStorageWritable()) {
  …
}

That is, notice Environment() and not Environment which means I have to create an instance of Environment first before using it.

It is currently not possible in Kotlin to provide static extension functions to existing java classes. See, https://discuss.kotlinlang.org/t/static-extension-methods-for-java-classes/2190

Therefore the extension functions provided by KEnvironment.kt is not usable or practical. I would say either removing it or changing them into top-level functions instead.