Very newbie question, I got this function
private fun getUrl() {
val storage = Firebase.storage
val storageRef = storage.reference
val gsReference = storageRef.child("bucket path")
val imageFolderReference = gsReference.child("images")
imageFolderReference.child("images/IMG.jpg")
.downloadUrl.addOnSuccessListener {
val url: String = it.toString()
}
}
it should return the URL of an image stored on a firebase cloud. How can I expose that url string outside of the functions tho? let's say to set a text view's text to that link.
Thanks in advance
Edit
I tried this
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val binding = DataBindingUtil.inflate<FragmentTestBinding>(inflater, R.layout.fragment_test, container,false)
val textView: TextView = binding.textView
getUrl {
textView.text = it
}
return binding.root
}
private fun getUrl(callback: (String) -> Unit) {
val storage = Firebase.storage
val storageRef = storage.reference
val gsReference = storageRef.child("gs path")
val imageFolderReference = gsReference.child("images")
imageFolderReference.child("images/IMG.jpg")
.downloadUrl.addOnSuccessListener {
val url = it.toString()
callback.invoke(url)
}
}
still the text view is empty..
And the callback never gets called..
here's the error logcat
2021-04-06 16:47:45.842 16149-16149/? E/m.pdl.giftpixe: Unknown bits set in runtime_flags: 0x8000
2021-04-06 16:47:46.978 16149-16149/com.pdl.giftpixel E/libc: Access denied finding property "ro.vendor.df.effect.conflict"
2021-04-06 16:47:46.990 16149-16235/com.pdl.giftpixel E/Perf: Fail to get file list com.pdl.giftpixel
2021-04-06 16:47:46.991 16149-16235/com.pdl.giftpixel E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2021-04-06 16:47:46.991 16149-16235/com.pdl.giftpixel E/Perf: Fail to get file list com.pdl.giftpixel
2021-04-06 16:47:46.991 16149-16235/com.pdl.giftpixel E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array