gpt4 book ai didi

android - 人行横道 web View 中的文件接受和捕获标签失败

转载 作者:太空宇宙 更新时间:2023-11-03 10:18:02 24 4
gpt4 key购买 nike

我试图在一个紧凑的应用程序中制作一个仅上传图片的输入字段,该应用程序基本上运行一个带有一些自定义脚本的人行横道 webview。

通过常规浏览器,使用如下标签:

<input type="file" accept="image/*;capture=camera" capture="camera">

或者 <input type="file" accept="image/*" capture="camera">按预期工作,将用户直接带到相机拍摄模式。

但出于某种原因,这个 ResolverActivity 面板出现在我的设备上:

This bloody resolver. Make it go away...

我真的希望它消失,让用户直接拍照。我的系统不支持视频(甚至更少的录音)。

我发现了一些与我正在处理的问题产生共鸣的错误报告,但它们也声明该错误已得到解决。唉,当我运行最新版的crosswalk时,这个bug还是出现了。

有没有人知道如何解决这个问题?也许一些 list 文件阻止了摄像机和录音的出现?

我已经尝试使用 xwalk_core_library_beta:15.44.384.2xwalk_core_library:14.43.343.23

如果不出意外,我将不得不编写一个手动上传过程。并非不可能,但我真的很想避免这种情况。

最佳答案

我是 Android 代码开发新手(2 天),所以请多多包涵。
该代码在 4.4.2 中为我工作:

<input type="file" accept="image/*" capture="camera">

很乱,但希望能帮助到一些人。

主要 Activity .java:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

xWalkWebView=(XWalkView)findViewById(R.id.xwalkWebView);
xWalkWebView.setUIClient(new UIClient(xWalkWebView));
xWalkWebView.load("http://your.url", null);
}

private ValueCallback<Uri> mFilePathCallback;
private String mCameraPhotoPath;
public static final int INPUT_FILE_REQUEST_CODE = 1;

class UIClient extends XWalkUIClient {

public void openFileChooser(XWalkView view, ValueCallback<Uri> uploadFile,
String acceptType, String capture) {

if(!(acceptType.toLowerCase().equals("image/*") && capture.equals("true"))){
super.openFileChooser(view, uploadFile, acceptType, capture);
return;
}


if(mFilePathCallback != null) {
mFilePathCallback.onReceiveValue(null);
}
mFilePathCallback = uploadFile;

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File photoFile = null;
try {
photoFile = createImageFile();
takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
} catch (IOException ex) {
Log.e(TAG, "Unable to create Image File", ex);
}

// Continue only if the File was successfully created
if (photoFile != null) {
mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photoFile));
} else {
takePictureIntent = null;
}


Intent contentSelectionIntent =new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE);

}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

if(requestCode != INPUT_FILE_REQUEST_CODE || mFilePathCallback == null) {
xWalkWebView.onActivityResult(requestCode, resultCode, data);
return;
}


Uri results = null;

// Check that the response is a good one
if(resultCode == Activity.RESULT_OK) {
if(data == null) {
// If there is not data, then we may have taken a photo
if(mCameraPhotoPath != null) {
results = Uri.parse(mCameraPhotoPath);
}
} else {
String dataString = data.getDataString();
if (dataString != null) {
results = Uri.parse(dataString);
}
}
}

mFilePathCallback.onReceiveValue(results);
mFilePathCallback = null;
return;

}



private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File imageFile = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
return imageFile;
}

关于android - 人行横道 web View 中的文件接受和捕获标签失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31988159/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com