在 webview 中嵌入云雀客服的一些问题
1. Android 无法发送图片
由于 Android 本身的限制,在 webview 中上传文件需要自行重载 `openFileChooser()` 或者 `onShowFileChooser()` 方法
大致代码如下, 更完整的示例可以自行搜索 「安卓 webview 上传文件」
webview.setWebChromeClient(new WebChromeClient() { // For Android < 3.0 public void openFileChooser(ValueCallback<Uri> valueCallback) { uploadMessage = valueCallback; openImageChooserActivity(); } // For Android >= 3.0 public void openFileChooser(ValueCallback valueCallback, String acceptType) { uploadMessage = valueCallback; openImageChooserActivity(); } //For Android >= 4.1 public void openFileChooser(ValueCallback<Uri> valueCallback, String acceptType, String capture) { uploadMessage = valueCallback; openImageChooserActivity(); } // For Android >= 5.0 @Override public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) { uploadMessageAboveL = filePathCallback; openImageChooserActivity(); return true; } });
2. Android 上用户唤起软键盘后会遮挡输入框
为 activity 指定 `android:windowSoftInputMode` 即可,值可以为 `adjustPan` 或者 `adjustResize`
<activity android:name=".MainActivity" android:label="@string/app_name" android:windowSoftInputMode="adjustPan"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
3. Vivo等手机留言界面提示无法发送
需要配置webview允许开启本地存储
webView.getSettings().setDomStorageEnabled(true);