2017-05-26 100 views
0

我不能让对话框选择一个文件,当我点击按钮选择文件在我的HTML!webview不允许我选择文件

webView=(WebView)findViewById(R.id.webview_upload_file); 

    webView.setWebViewClient(new WebViewClient()); 
    webView.getSettings().setBuiltInZoomControls(true);  
    webView.getSettings().setAllowFileAccess(true); 
    webView.getSettings().setSupportZoom(true); 
    webView.getSettings().setAllowContentAccess(true); 
    webView.getSettings().setJavaScriptEnabled(true); 
    webView.getSettings().setAllowFileAccess(true); 

webView.loadUrl(link); 

回答

0

,我认为你必须使用Android的意图做浏览文件

检查此线路上

webView.setWebChromeClient(new WebChromeClient() 
{ 
     //The undocumented magic method override 
     //Eclipse will swear at you if you try to put @Override here 
     // For Android 3.0+ 
    public void openFileChooser(ValueCallback<Uri> uploadMsg) { 

     mUploadMessage = uploadMsg; 
     Intent i = new Intent(Intent.ACTION_GET_CONTENT); 
     i.addCategory(Intent.CATEGORY_OPENABLE); 
     i.setType("image/*"); 
     MyWb.this.startActivityForResult(Intent.createChooser(i,"File Chooser"), FILECHOOSER_RESULTCODE); 

     } 

    // For Android 3.0+ 
     public void openFileChooser(ValueCallback uploadMsg, String acceptType) { 
     mUploadMessage = uploadMsg; 
     Intent i = new Intent(Intent.ACTION_GET_CONTENT); 
     i.addCategory(Intent.CATEGORY_OPENABLE); 
     i.setType("*/*"); 
     MyWb.this.startActivityForResult(
     Intent.createChooser(i, "File Browser"), 
     FILECHOOSER_RESULTCODE); 
     } 

    //For Android 4.1 
     public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture){ 
      mUploadMessage = uploadMsg; 
      Intent i = new Intent(Intent.ACTION_GET_CONTENT); 
      i.addCategory(Intent.CATEGORY_OPENABLE); 
      i.setType("image/*"); 
      MyWb.this.startActivityForResult(Intent.createChooser(i, "File Chooser"), MyWb.FILECHOOSER_RESULTCODE); 

     } 

}); 

的完整代码,请检查此链接:android file upload

相关问题