如何有意启动前置摄像头? [英] How to launch front camera with intent?

查看:24
本文介绍了如何有意启动前置摄像头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Intent 通过本机应用程序打开相机:

I'm using an intent to open the camera with the native application:

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    Uri photoUri = Uri.fromFile(getOutputPhotoFile());
    intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);

    startActivityForResult(intent, CAMERA_PHOTO_REQUEST_CODE);

每次打开相机(前置/后置相机)就像上次打开这个原生相机应用程序一样.这意味着如果我上次关闭本机相机应用程序时后置摄像头处于活动状态,那么当我启动相机的意图时,后置摄像头将处于活动状态.

Every time the camera that is opened (front/back camera) is like the last time this native camera application was open. Meaning that if the last time I closed the native camera application the back camera was active, so when I launch the intent for camera, the back camera will be active.

我想直接启动前置摄像头.有人知道怎么做吗?

I want to launch directly the front camera with the intent. Does anybody know how to do that?

推荐答案

警告:这是一个黑客

将此添加到意图

intent.putExtra("android.intent.extras.CAMERA_FACING", 1);

这个解决方案是不可持续的,它使用了相机应用的测试代码.有关详细信息,请查看 AOSP 相机项目的 Util 类中的getCameraFacingIntentExtras"静态方法.

This solution isn't sustainable, its using a testing code of the Camera app. For more info look at the "getCameraFacingIntentExtras" static method in Util class of the AOSP Camera project.

更新:看起来它在 L 中被禁用

Update: Looks like that it was disabled in L

这篇关于如何有意启动前置摄像头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆