0

In onShowFileChooser(WebView view, ValueCallback<Uri[]> filePath, WebChromeClient.FileChooserParams fileChooserParams) function gives filePath to null;

Device configuration:
Debug-infos:
Android version: 21
Device: samsung SM-N9005
OS Version: 3.4.0-6408191(N9005DXSGBQA1)
Device: hlte

In other devices and api level it is working fine.

webView.setWebChromeClient(new WebChromeClient() {

        // For Android 5.0
        public boolean onShowFileChooser(WebView view, ValueCallback<Uri[]> filePath, WebChromeClient.FileChooserParams fileChooserParams) {

            //qrCodeReaderView.stopCamera();
            mFilePathCallback = filePath;
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            File photoFile = null;
            try {
                photoFile = createImageFile();
            } catch (IOException e) {
                e.printStackTrace();
            }

            mCapturedImageURI = Uri.fromFile(photoFile);
            if (photoFile != null) {
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI
                );
            } else {

            }
            startActivityForResult(takePictureIntent, INPUT_FILE_REQUEST_CODE);

            return true;

        }

    });

On activity result:

 @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data);       
     mFilePathCallback.onReceiveValue(new Uri[]{mCapturedImageURI});   
     mFilePathCallback = null;
   }

Logcat:

java.lang.RuntimeException: 
Unable to resume activity   
{com.gaintz/com.shashank.gaintz.WebViewActivity}:  
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=null} to activity  {com.gaintz/com.shashank.gaintz.WebViewActivity}: 

java.lang.NullPointerException: Attempt to invoke interface method 'void android.webkit.ValueCallback.onReceiveValue(java.lang.Object‌​)' on a null object reference at android.app.ActivityThread.performResumeActivity(ActivityThr‌​ead.java:3390) at 
Ratilal Chopda
  • 4,162
  • 4
  • 18
  • 31

1 Answers1

0

I know it's too late for leaving an answer now but I had same problem and I solved it so leaving an answer for future readers.

I faced this issue only on Android Lollipop(Samsung galaxy s4, note3).

Whenever I take a picture, filePath was always null.

Through many tests, I realized the webview was refreshed every time when we take a picture.

The reason why it has been refreshed was the 'Activity orientation'.

Add this in Menifest to keep origin orentation status of your activity which has the webview.

<activity 
 ...
 android:configChanges="orientation|screenSize">

Also you can refer to Android - Preventing WebView reload on Rotate

Ian
  • 53
  • 5