如何在Android中启动相机

问题描述 投票:0回答:1

我正在了解Android源代码中提供的Android Camera的代码流程。当我们从家庭活动中打开相机时,谁能告诉我相机活动中哪种方法负责调用相机硬件?

我签入Camera.java(用户从家中启动摄像机时调用的第一个活动,但没有找到任何合适的路径。

android android-camera android-source
1个回答
2
投票

创建意图以启动Camera应用程序:

private static final int CAMERA_PIC_REQUEST = 9999; // this can be anything
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); 

处理从相机获得的结果:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    if (requestCode == CAMERA_PIC_REQUEST) {  
        Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); // this is the picture taken  
    }  
}

要在您的应用程序中使用相机,您还需要请求特殊权限。将其放入清单文件中:

<uses-feature android:name="android.hardware.camera"></uses-feature> 
© www.soinside.com 2019 - 2024. All rights reserved.