【发布时间】:2019-11-13 10:19:34
【问题描述】:
我正在开发一个 webview 应用程序。到目前为止,当用户使用MediaStore.ACTION_IMAGE_CAPTURE 点按文件输入时,我已经设法直接打开相机。
但是,相机操作会打开股票相机应用程序,但不会在右下角显示现有的图像选择器。然而,当我从我的应用程序外部打开股票相机应用程序时,右下角有一个圆圈,带有图像预览,就在快门按钮旁边。
我怎样才能让这个按钮也显示在我的应用程序中? 显然我试图通过谷歌搜索找到它,但我只能找到关于如何向用户显示一个对话框的答案,他们可以从相机或画廊中选择一张照片。但没有关于如何在相机动作中显示“从画廊中挑选”按钮。 如果有人能指出我正确的方向,那将非常感激:)
这是我正在使用的完整方法:
override fun onShowFileChooser(
webView: WebView?,
filePathCallback: ValueCallback<Array<Uri>>?,
fileChooserParams: WebChromeClient.FileChooserParams?
): Boolean {
val takePictureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
// Double check that we don't have any existing callbacks
this@WebClient.filePathCallback?.onReceiveValue(null)
this@WebClient.filePathCallback = filePathCallback
if (takePictureIntent.resolveActivity(activity.packageManager) != null) {
// create file where image should go
var photoFile: File? = null
try {
photoFile = createImageFile()
takePictureIntent.putExtra("PhotoPath", cameraPhotoPath)
} catch (exception: IOException) {
Log.e("imageError", "Unable to create image file", exception)
}
if (photoFile != null) {
cameraPhotoPath = "file:${photoFile.absolutePath}"
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile))
}
}
val contentSelectionIntent = Intent(Intent.ACTION_CHOOSER).apply {
addCategory(Intent.CATEGORY_OPENABLE)
this.type = "image/*"
}
val chooserIntent = Intent(Intent.ACTION_CHOOSER).apply {
putExtra(Intent.EXTRA_INTENT, contentSelectionIntent)
putExtra(Intent.EXTRA_INITIAL_INTENTS, arrayOf(takePictureIntent))
}
activity.startActivityForResult(chooserIntent, inputFileRequestCode)
return true
}
【问题讨论】:
标签: android kotlin android-intent android-camera-intent