There is no error and no problem with clicking the button, but the voice file does not upload to the Firestore. Audio selection is possible, but the message "Successfully Uploaded:" is not output, and the voice file is not uploaded to the Fire Store. I think the cancellation line in onActivityResult and startActivityForResult is the problem. How do I get rid of the cancellation line? And is there any other reason why the file doesn't go up on the fire store?
++I modified the Firestore rules.
MainActivity.kt
import ...
class MainActivity : AppCompatActivity() {
val AUDIO : Int = 0
lateinit var uri: Uri
lateinit var mStorage: StorageReference
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val musicBtn = findViewById<View>(R.id.musicBtn) as Button
mStorage = FirebaseStorage.getInstance().getReference("Uploads")
musicBtn.setOnClickListener(View.OnClickListener {
view -> val intent = Intent()
intent.setType("audio/*")
intent.setAction(Intent.ACTION_GET_CONTENT)
startActivityForResult(Intent.createChooser(intent, "Select MP3"), AUDIO)
})
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
val uriTxt = findViewById<View>(R.id.uriTxt)as TextView
if (requestCode== RESULT_OK){
if (requestCode == AUDIO) {
uri = data!!.data!!
uriTxt.text = uri.toString()
upload()
}
}
super.onActivityResult(requestCode, resultCode, data)
}
private fun upload() {
var mReference = mStorage.child(uri.lastPathSegment!!)
try {
mReference.putFile(uri).addOnSuccessListener {
taskSnapshot: UploadTask.TaskSnapshot? -> var url = taskSnapshot!!
val dwnTxt = findViewById<View>(R.id.dwnTxt) as TextView
dwnTxt.text = url.toString()
Toast.makeText(this, "Successfully Uploaded :)", Toast.LENGTH_LONG).show()
}
}catch (e: Exception) {
Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show()
}
}
}
A cancellation line is created as shown in the image. How do I solve it?