【发布时间】:2019-08-05 08:15:36
【问题描述】:
我正在尝试获取一个文件并将该文件传递给 Firebase 并将其存储在我的存储桶中,但由于某种原因,即使按照另一个建议将属性 android:launchMode="singleTop" 添加到清单文件后,我的 startActivityForResult 也没有被调用回答,也不要在我的按钮单击事件上使用 kotlin 静态函数调用,该事件应该启动意图。请注意两者都在同一个活动中!
这是我的按钮点击处理程序:
override fun onCreate(savedInstanceState: Bundle?) {
btnImage.setOnClickListener {
val intent = Intent()
intent.action = Intent.ACTION_GET_CONTENT
// set the intent type
intent.type = "image/*"
// accept only local content
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true)
startActivityForResult(Intent.createChooser(intent, "Insert Picture"), PICTURE_RESULT)
}
}
这是我的 startAtivityForResult 函数:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
// super.onActivityResult(requestCode, resultCode, data)
if (resultCode == PICTURE_RESULT && resultCode == Activity.RESULT_OK) {
if (data != null) {
val imageUri : Uri = data.data!!
val ref : StorageReference = FirebaseUtil.storageRef!!.child(imageUri.lastPathSegment!!)
ref.putFile(imageUri)
{
} else {
Log.d("IMAGE", resultCode.toString())
Toast.makeText(this, "Upload failure", Toast.LENGTH_LONG).show()
}
}
}
【问题讨论】:
-
你使用的是片段还是活动?
-
活动,是我正在使用的
-
你能检查一次 resultCode 和 request code 以及 PICTURE_RESULT 值吗
标签: android android-intent android-activity kotlin