项目中遇到  H5的input type="file" 标签在android的webview中失效,查了一下是安卓禁用掉了

 重写webview 的WebChromeClient 可以解决 

 webView.setWebChromeClient(new WebChromeClient(){                      // For 3.0+ Devices (Start)            // onActivityResult attached before constructor            protected void openFileChooser(ValueCallback uploadMsg, String acceptType)            {                mUploadMessage = uploadMsg;                Intent i = new Intent(Intent.ACTION_GET_CONTENT);                i.addCategory(Intent.CATEGORY_OPENABLE);                i.setType("image/*");                startActivityForResult(Intent.createChooser(i, "File Browser"), FILECHOOSER_RESULTCODE);            }            // For Lollipop 5.0+ Devices            @TargetApi(Build.VERSION_CODES.LOLLIPOP)            @Override            public boolean onShowFileChooser(WebView webView, ValueCallback filePathCallback, FileChooserParams fileChooserParams) {                if (uploadMessage != null) {                    uploadMessage.onReceiveValue(null);                    uploadMessage = null;                }                uploadMessage = filePathCallback;                Intent intent = fileChooserParams.createIntent();                try                {                    startActivityForResult(intent, REQUEST_SELECT_FILE);                } catch (ActivityNotFoundException e)                {                    uploadMessage = null;                    Toast.makeText(getBaseContext(), "Cannot Open File Chooser", Toast.LENGTH_LONG).show();                    return false;                }                return true;            }            //For Android 4.1 only            protected void openFileChooser(ValueCallback uploadMsg, String acceptType, String capture)            {                mUploadMessage = uploadMsg;                Intent intent = new Intent(Intent.ACTION_GET_CONTENT);                intent.addCategory(Intent.CATEGORY_OPENABLE);                intent.setType("image/*");                startActivityForResult(Intent.createChooser(intent, "File Browser"), FILECHOOSER_RESULTCODE);            }            protected void openFileChooser(ValueCallback uploadMsg) {                mUploadMessage = uploadMsg;                Intent i = new Intent(Intent.ACTION_GET_CONTENT);                i.addCategory(Intent.CATEGORY_OPENABLE);                i.setType("image/*");                startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);            }        });

   
@Override    protected void onActivityResult(int requestCode, int resultCode, Intent data) {        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {            if (requestCode == REQUEST_SELECT_FILE)            {                if (uploadMessage == null)                    return;                uploadMessage.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, data));                uploadMessage = null;            }        }        else if (requestCode == FILECHOOSER_RESULTCODE) {            if (null == mUploadMessage)                return;            // Use MainActivity.RESULT_OK if you're implementing WebView inside Fragment            // Use RESULT_OK only if you're implementing WebView inside an Activity            Uri result = data == null || resultCode != NewQuanZi.RESULT_OK ? null : data.getData();            mUploadMessage.onReceiveValue(result);            mUploadMessage = null;        }        else            Toast.makeText(getBaseContext(), "选择图片失败", Toast.LENGTH_LONG).show();    }
可以解决3.1  4.1 5.0以上的版本的问题


更多相关文章

  1. 解决Warning:android-apt plugin is incompatible with future v
  2. GridView, ListView
  3. Android(安卓)软件盘弹出时把顶部局顶上去的解决方法
  4. Android(安卓)Studio 配置SVN报错解决
  5. android 隐藏虚拟按键
  6. 两种button点击后改变颜色的方法selectot和重写
  7. Android(安卓)Things APP版本更新解决方案
  8. Android设备开发中的一些解决办法
  9. Android全屏时软键盘遮住输入框修改布局解决方案

随机推荐

  1. Android(安卓)MediaCodec 硬编码器封装
  2. android中简单的图片翻页效果
  3. Android 存储设备管理 -- IMountService (二
  4. android按Menu出现菜单的动画
  5. 刚学android,练手写的一个播放器
  6. Android 给GridView添加分割线
  7. android sd 卡操作
  8. Android9.0 修改状态栏图标之间的间距
  9. android 获取设备Id等信息
  10. Android简单实现启动画面的方法