java Web视图文件选择器崩溃问题
在onShowFileChooser中(WebView view, ValueCallback<Uri[]> filePath, WebChromeClient.FileChooserParams fileChooserParams)
函数将filePath
设为null
Device configuration:
Debug-infos:
Android version: 21
Device: samsung SM-N9005
OS Version: 3.4.0-6408191(N9005DXSGBQA1)
Device: hlte
在其他设备和api级别,它工作正常
webView.setWebChromeClient(new WebChromeClient() {
// For Android 5.0
public boolean onShowFileChooser(WebView view, ValueCallback<Uri[]> filePath, WebChromeClient.FileChooserParams fileChooserParams) {
//qrCodeReaderView.stopCamera();
mFilePathCallback = filePath;
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException e) {
e.printStackTrace();
}
mCapturedImageURI = Uri.fromFile(photoFile);
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI
);
} else {
}
startActivityForResult(takePictureIntent, INPUT_FILE_REQUEST_CODE);
return true;
}
});
关于活动结果:
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mFilePathCallback.onReceiveValue(new Uri[]{mCapturedImageURI});
mFilePathCallback = null;
}
日志:
java.lang.RuntimeException:
Unable to resume activity
{com.gaintz/com.shashank.gaintz.WebViewActivity}:
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=null} to activity {com.gaintz/com.shashank.gaintz.WebViewActivity}:
java.lang.NullPointerException: Attempt to invoke interface method 'void 安卓.webkit.ValueCallback.onReceiveValue(java.lang.Object)' on a null object reference at 安卓.app.ActivityThread.performResumeActivity(ActivityThread.java:3390) at
# 1 楼答案
我知道现在给出答案已经太迟了,但我也有同样的问题,我解决了,所以给未来的读者留下了答案
我只在安卓棒棒糖上遇到过这个问题(三星galaxy s4,注3)
每当我拍照时,文件路径总是空的
通过多次测试,我意识到每次拍照时网络视图都会刷新
刷新的原因是“活动导向”
将此添加到Menifest中,以保持具有webview的活动的起源或定位状态
你也可以参考Android - Preventing WebView reload on Rotate