Android 9.0 Camera2 camera function selects the front camera by default

1 Overview


 In the 9.0 system product development, it is also a common function for the app to call the system api to open the camera to take pictures, and the picture is generally opened by default to open the rear camera to take pictures. Due to the special requirements of the customer's product, it is necessary to open the front camera to take
pictures function, so you need to understand the process of the camera function, and then modify the default front camera to open the camera function.

The app calls the camera function as follows:

    private void photograph(String outputimagepath){
    try//判断图片是否存在,存在则删除在创建,不存在则直接创建
     
    {
     
    if (!outputimagepath.getParentFile().exists()) {
     
    outputimagepath.getParentFile().mkdirs();
     
    }
     
    if (outputimagepath.exists()) {
     
    outputimagepath.delete();
     
    }
     
    outputimagepath.createNewFile();
    Uri imagUri = null;
    if (Build.VERSION.SDK_INT >= 24) {
     
    imageUri = FileProvider.getUriForFile(this,
     
    "com.wj.phone.fileprovider", outputimagepath);
     
    } else {
     
    imageUri = Uri.fromFile(outputimagepath);
     
    }
     
    //使用隐示的Intent,系统会找到与它对应的活动,即调用摄像头,并把它存储
     
    Intent 

Guess you like

Origin blog.csdn.net/baidu_41666295/article/details/130586364