android - 关于webview加载服务器端的h5页面
PHPz
PHPz 2017-04-17 16:28:41
0
4
472

1.先说说项目的一个场景吧,BOSS希望ios和Android端能够加载h5页面,这样才能动态满足各式各样的需求变化,也能够减少ios和Android的开发工作量(只需要维护用原生编写的代码即可,H5页面的功能由前端开发维护),本来我们开发人员觉得这样子好像蛮好的,因为纯粹如果只是加载h5页面,展示和填写一些数据而已,但是后来发现还需要在H5页面上传图片,ios端的webview能够直接就唤醒摄像头和相册,而安卓并不能够直接就调用,在网上查找了很多资料,都说需要重写webview的WebChromeClient的openChooseFile方法。
2.为了探究这个可行性,还叫前段写了一个页面去测试,ios的webview直接弹出照相机和相册的菜单,但是Android并不是所有机子都行,不过发现UC浏览器和Chrome都能够弹出。
3.基于UC和Chrome都能打开的原因,我觉得肯定是有解决的办法的
4.求各位大神指导,有什么办法能够实现一个强大的能够适配大部分H5页面的webview呢?

PHPz
PHPz

学习是最好的投资!

reply all(4)
迷茫

You might as well use cordova for development! http://blog.csdn.net/dabaoonline/article/details/50820015 This becomes a matter of js.

PHPzhong

cordova

洪涛

You should also consider the api version:

public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
                                             FileChooserParams fileChooserParams) {
                if( fileChooserParams != null){
                    if( android.os.Build.VERSION.SDK_INT >= 21) {
                        mFileChooserCallback = filePathCallback;
                        Intent intent = fileChooserParams.createIntent();
                        try{
                            getActivity().startActivityForResult(intent,200);
                        }catch (Exception e){
                            mFileChooserCallback = null;
                            e.printStackTrace();
                            return false;
                        }
                    }
                }
                return true;
            }
            public void openFileChooser(ValueCallback<Uri> uploadFile, String acceptType, String capture) {
                if( android.os.Build.VERSION.SDK_INT < 21) {
                    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);  
                intent.setType("*/*");
                intent.addCategory(Intent.CATEGORY_OPENABLE);
//                    if(mLastSelectFileDir != null && mLastSelectFileDir.length() > 0) {
//                        i.putExtra("init_directory", mLastSelectFileDir);
//                    }
                    mFileChooserCallbackV19 = uploadFile;
                    try{
                        getActivity().startActivityForResult(intent,200);
                    }catch (Exception e){
                        mFileChooserCallbackV19 = null;
                        e.printStackTrace();
                    }
                    uploadFile.onReceiveValue(null);
                }
            }
        });
大家讲道理

I don’t know if the poster has encountered this problem. The h5 page adjustment interface of webview has been unable to return results and reported an error. But it is normal to access the h5 page in the browser

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!