Android ios in webapp only calls the camera method

Android ios in webapp only calls the camera method

Happy work, so many problems. (O(╥﹏╥)o) A
new problem in webapp, to solve a problem that when you click in the uploaded picture, you can't call the album when you call the camera directly. (What kind of operation, silly)
I only remember that the capture attribute can directly call the camera, video and other functions, but the multiple attribute that can be selected is removed . The first attempt has failed, but this can be used in ios , then The problem to be solved is Android.
I don't know what to do, ask Baidu Baba, the crazy Baidu mode has started, and there is still no solution, so I can only get rid of the Android boss and write a method. Hehehe, here
is your favorite code example

Front end call method

Because it is possible to support only calling the camera in ios, it is agreed with Android to change the value in accept to make the app directly open the camera
. 1. Before modification

 <input type="file" capture="camera" ng-model="vm.avatarFile1" ngf-accept="'image/*'">

2. After modification

 <input type="file" capture="camera" ng-model="vm.avatarFile1" ngf-accept="'bugdd/*'">

Android shell code

The meaning of this code is probably to get the parameter in accept and determine whether it contains the parameter he needs. If it contains, call the camera method, if not, call the camera and album methods.

@Override
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
    
    
    String[] acceptTypes = fileChooserParams.getAcceptTypes();
    mOpenFileChooserCallBack.showFileChooserCallBack(filePathCallback, acceptTypes);
    return true;
}

public interface OpenFileChooserCallBack {
    
    
    void openFileChooserCallBack(ValueCallback<Uri> uploadMsg, String acceptType);
    void showFileChooserCallBack(ValueCallback<Uri[]> filePathCallback, String[] acceptTypes);
}


@Override
public void showFileChooserCallBack(ValueCallback<Uri[]> filePathCallback, String[] acceptType) {
    
    
    mUploadMsg5Plus = filePathCallback;
    showOptions(acceptType[0]);
}

public void showOptions(String acceptType) {
    
    
    if (acceptType.indexOf("bugdd")) {
    
    //判断accept中是否有这个参数
        startCamera();
    } else {
    
    
        AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
        alertDialog.setOnCancelListener(new ReOnCancelListener());
        alertDialog.setItems(array.options, new DialogInterface.OnClickListener() {
    
    
            @Override
            public void onClick(DialogInterface dialog, int which) {
    
    
                /**
                 * 相册
                 */
                if (which == 0) {
    
    

                    startPicture();
                }
                /**
                 * 拍照
                 */
                if (which == 1) {
    
    

                    //启动相机
                    startCamera();
                }
            }
        });
        alertDialog.show();
    }
}


/**
 * 启动选择照片
 */
private void startPicture() {
    
    

    if (!checkPermission(MyConstant.img_permissions, REQUEST_CODE_PICK_IMAGE_PER)) {
    
    
        return;
    }

    pick_imageIntent = ImageUtil.choosePicture();
    startActivityForResult(pick_imageIntent, REQUEST_CODE_PICK_IMAGE);
}


/**
 * 打开相机获取图片
 */
private void startCamera() {
    
    

    if (!this.checkPermission(MyConstant.photo_permissions, REQUEST_CODE_IMAGE_CAPTURE_PER)) {
    
    
        return;
    }

    image_captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    //判断是否有相机应用
    if (image_captureIntent.resolveActivity(getPackageManager()) == null) {
    
    
        //无相机
        Toast.makeText(this, "无法打开相机", Toast.LENGTH_SHORT).show();
        return;
    }
    //设置兼容配置 主要考虑 Android N
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
    
    

        //申请权限
        image_captureIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        image_captureIntent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        //
    }

    try {
    
    

        photoFile = createImageFile();
    } catch (Exception ex) {
    
    
        ex.printStackTrace();
    }

    if (photoFile != null) {
    
    
        contentUri = FileProvider.getUriForFile(this,
                "com.zrbx.yzs.fileProvider",
                photoFile);

    }

    image_captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);
    startActivityForResult(image_captureIntent, REQUEST_CODE_IMAGE_CAPTURE);
}

Guess you like

Origin blog.csdn.net/lbchenxy/article/details/98481699