2017-05-26 85 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