2016-04-28 21 views
1

私は自分のアンドロイドアプリケーションを作成していますが、これはファイルアップロードが90%必要です。ファイルアップロードAndroid 4.4 WebView

WebView Lollipopコードを取得しましたが、うまくいきましたが、Android 4.4でファイルセレクタを開くと入力が機能しません。

誰でも手伝えますか?ここに私のコードです:

mWebView.setWebChromeClient(new WebChromeClient() { 

     public boolean onShowFileChooser(
       WebView webView, ValueCallback<Uri[]> filePathCallback, 
       WebChromeClient.FileChooserParams fileChooserParams) { 
      if(mFilePathCallback != null) { 
       mFilePathCallback.onReceiveValue(null); 
      } 
      mFilePathCallback = filePathCallback; 

      Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
      if (takePictureIntent.resolveActivity(getActivity().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; 
       } 
      } 

      Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT); 
      contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE); 
      contentSelectionIntent.setType("image/*"); 

      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, "Escoge tu imagen"); 
      chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray); 

      startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE); 

      return true; 
     } 
    }); 

答えて

-1

私はあなたのコードを試して、問題を見てきました。これらのすべてのアンドロイドデバイスで動作するcode exampleをチェックして、webviewclientとwebchromeクライアントを使用してアンドロイドアプリケーションに画像ファイルをアップロードすることができます。

0

Android 4.4にはファイル入力を壊したWebViewのバグがあります。私の回避策は、Javascriptを使ってアプリとウェブサイトとの間でやりとりし、ユーザーがいつファイルをアップロードしてアプリから(ウェブビューの外に)アップロードしたいかを検出し、ファイルが読み込まれたらwebviewを更新してファイルがサーバーにあるWebサイト。

私の解決方法をここで説明します。 https://stackoverflow.com/a/43443981/2566593