我可以强制我的应用程序启动默认相机而不是提供“使用完成操作”吗?列表?
我正在使用意图 new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 来捕获图像以在我的应用程序中使用。我的设备上安装了两个可以执行此功能的应用程序,但希望我的应用程序仅使用默认摄像头。
有办法做到这一点吗?
I'm using the intent new Intent(MediaStore.ACTION_IMAGE_CAPTURE); to capture an image for use in my application. I have two applications installed on my device that can perform this function but would like my app to only use the default camera.
Is there a way of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
正如 Dr_sulli 所建议的,我只是将其转换为代码,它对我来说效果很好,如果需要访问直接相机应用程序,其他部分是允许用户选择其他相机应用程序以及系统相机。
在 onActivityResult 中做你的事情
isPackageExists 将确认包是否存在。
或者您可以按照我的方式进行操作,这要容易得多,这将过滤所有系统应用程序,然后您比较名称,因此它适用于所有手机,但由于硬编码,上述技术并不适用于每部手机。稍后您可以使用此包名称来启动相机活动,如上所述。
As Dr_sulli suggested, i am just converting it into a code and it works for me well, If case to access direct camera application and else part is allow the user to choose other camera applications along with system camera.
inside onActivityResult do your stuff
isPackageExists will confirm the package exist or not.
OR you can do it in my way its much easier, this will filter the all system application and then later you compare the name hence it work on all phone but the above technique due to hard coding will not work on every phone. Later you can use this package name to start the camera activity as i described above.
我发现以下解决方案及其工作完美。
您可以通过在上面的意图中设置包来过滤默认相机。我通过安装两个应用程序线相机和纸相机进行了测试,这两个应用程序都显示选择器,但按上面的代码包仅打开默认相机。
I find following solution and its working perfectly.
you can filter default camera by setting package in above intent. I've tested it by installing two application Line Camera and Paper Camera both apps were showing chooser but filtering by package above code open only default camera.
我准备了一个适用于几乎所有解决方案的解决方案:
您可能需要在 onCreate 方法中添加以下代码:
I have prepared a solution which works in almost all solution:
You may need to put following code in onCreate method:
我不确定您想要完成的任务是否可以跨所有设备移植。 Android 的目标之一是允许轻松替换服务请求(例如图像捕获)的活动。话虽这么说,如果您只想为您的设备执行此操作,您可以简单地将意图中的组件名称设置为媒体捕获活动的名称。
I'm not sure what you are trying to accomplish is portable across all devices. One goal of Android is to allow the easy replacement of activities that service requests such as image capture. That being said, if you only wish to do this for your device, you could simply set the component name in the intent to the media capture activity's name.
默认相机应用程序是安装的第一个应用程序。因此,camlist 中的第一个元素是默认应用程序
the default camera app is the first app was installed. So, the first element in camlist is the default app