2015-08-13 36 views
1

我想讓我的webview與android 5.0兼容以獲取上傳文件的目的。我的構建目標是API19 4.4.2。我已經下載5.0 sdk和它的依賴關係。我得到一個錯誤WebChromeClient.FileChooserParams無法解析到一個類型Android:5.0:WebChromeClient.FileChooserParams不能解析爲

我在Stackoverflow上找到了這段代碼。

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

      webView.setWebChromeClient(new WebChromeClient() { 
       public boolean onShowFileChooser(
         WebView webView, ValueCallback<Uri[]> filePathCallback, 
         WebChromeClient.FileChooserParams fileChooserParams) { 

        // Double check that we don't have any existing callbacks 
        if(mFilePathCallback != null) { 
         mFilePathCallback.onReceiveValue(null); 
        } 
        mFilePathCallback = filePathCallback; 

        // Set up the take picture intent 
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
        if (takePictureIntent.resolveActivity(MainActivity.this.getPackageManager()) != null) { 
         // Create the File where the photo should go 
         File photoFile = null; 
         try { 
          photoFile = createImageFile(); 
          takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath); 
         } catch (IOException ex) { 
          // Error occurred while creating the File 
          Log.e(TAG, "Unable to create Image File", ex); 
         } 

         // Continue only if the File was successfully created 
         if (photoFile != null) { 
          mCameraPhotoPath = "file:" + photoFile.getAbsolutePath(); 
          takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, 
            Uri.fromFile(photoFile)); 
         } else { 
          takePictureIntent = null; 
         } 
        } 

        // Set up the intent to get an existing image 
        Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT); 
        contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE); 
        contentSelectionIntent.setType("image/*"); 

        // Set up the intents for the Intent chooser 
        Intent[] intentArray; 
        if(takePictureIntent != null) { 
         intentArray = new Intent[]{takePictureIntent}; 
        } else { 
         intentArray = new Intent[0]; 
        } 

        Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER); 
        chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent); 
        chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser"); 
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray); 

        startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE); 

        return true; 
       } 
     }); 

問題 enter image description here

+0

我沒有找到關於此stackoverflow的答案... –

回答

2

WebChromeClient.FileChooserParams是新的API等級21,因爲是onShowFileChooser()方法。因此,您需要將您的compileSdkVersion(也就是Eclipse中的「構建目標」)設置爲21,否則這些符號將不會被識別。

+0

如何做到這一點先生? –

+1

完成感謝您的幫助 –

相關問題