简体   繁体   English

在 Kotlin 中仅使用 android 相机意图拍照,而不是视频

[英]Take picture only with android camera intent in Kotlin, not video

I am using the following Kotlin code to open the camera on a simple Android App and take a user profile picture.我正在使用以下 Kotlin 代码在一个简单的 Android 应用程序上打开相机并拍摄用户个人资料图片。 I want to only take pictures, NOT video.我只想拍照,不想视频。 When I start the activity and the camera opens it also lets me record video.当我开始活动并打开相机时,它还可以让我录制视频。

val contentVvalues = ContentValues()
contentValues.put(MediaStore.Images.Media.MIME_TYPE, "image/jpg")
contentValues.put(MediaStore.Images.Media.TITLE, "My Picture")
contentValues.put(MediaStore.Images.Media.DESCRIPTION, "My first picture")
this.imageURI = contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues)

val cameraIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageURI)

startActivityForResult(cameraIntent, ACTION_IMAGE_CAPTURE_CODE)

I was wondering in anyone could help me with how I could go about having the image controls only?我想知道任何人都可以帮助我如何只使用图像控件?

I also notice I get the stickers and other controls.我还注意到我得到了贴纸和其他控件。 How do I remove those?我如何删除这些?

Thanks for the help!谢谢您的帮助!

When I start the activity and the camera opens it also lets me record video.当我开始活动并打开相机时,它还可以让我录制视频。

There are ~2.5 billion Android devices, spread across ~26,000 device models. Android 设备约有 25 亿台,分布在约 26,000 种设备型号中。 There will be dozens, if not hundreds, of pre-installed camera apps across those device models that might respond to ACTION_IMAGE_CAPTURE .在可能响应ACTION_IMAGE_CAPTURE设备型号中,将有数十个(如果不是数百个)预安装的相机应用程序。 There are also dozens, if not hundreds, of camera apps that the user might have installed that might respond to ACTION_IMAGE_CAPTURE .用户可能已经安装了数十个(如果不是数百个)相机应用程序,它们可能会响应ACTION_IMAGE_CAPTURE Your code could be starting any of those hundreds of apps.您的代码可能会启动这数百个应用程序中的任何一个。

And what a camera app does is up to the developers of the camera app, not you.相机应用程序的功能取决于相机应用程序的开发人员,而不是您。

I also notice I get the stickers and other controls.我还注意到我得到了贴纸和其他控件。 How do I remove those?我如何删除这些?

You don't.你没有。 That is the choice of the camera app developers.这是相机应用程序开发人员的选择。

In the case of offering both still image and video capture, that's arguably a bug in that particular camera app.在提供静态图像和视频捕获的情况下,这可以说是该特定相机应用程序中的一个错误。 There is very little that you can do about that.对此您无能为力。

I was wondering in anyone could help me with how I could go about having the image controls only?我想知道任何人都可以帮助我如何只使用图像控件?

Stop using ACTION_IMAGE_CAPTURE .停止使用ACTION_IMAGE_CAPTURE Write your own camera code, probably using a library (Google's CameraX, Fotoapparat, CameraKit-Android, etc.).编写您自己的相机代码,可能使用库(Google 的 CameraX、Fotoapparat、CameraKit-Android 等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM