Skip to content Skip to sidebar Skip to footer

Webview, File Input Field Filechooser Doesn't Show Up

I have been working hard trying to upload files from a webview. I tried many solutions but none worked. http://m0s-programming.blogspot.tw/2011/02/file-upload-in-through-webview-on

Solution 1:

Refer this Documentation :

https://infeeds.com/d/CODEmgks/20475/upload-image-file-gallery-or-camera-webv

publicbooleanonShowFileChooser(
     WebView webView, ValueCallback<Uri[]> filePathCallback,
     WebChromeClient.FileChooserParams fileChooserParams){
     if(mUMA != null){
          mUMA.onReceiveValue(null);
     }
     mUMA = filePathCallback;
     IntenttakePictureIntent=newIntent(MediaStore.ACTION_IMAGE_CAPTURE);
     if(takePictureIntent.resolveActivity(MainActivity.this.getPackageManager()) != null){
          FilephotoFile=null;
          try{
               photoFile = createImageFile();
               takePictureIntent.putExtra("PhotoPath", mCM);
          }catch(IOException ex){
               Log.e(TAG, "Image file creation failed", ex);
          }
          if(photoFile != null){
               mCM = "file:" + photoFile.getAbsolutePath();
               takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
          }else{
               takePictureIntent = null;
          }
     }
     IntentcontentSelectionIntent=newIntent(Intent.ACTION_GET_CONTENT);
     contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
     contentSelectionIntent.setType("image/*");
     Intent[] intentArray;
     if(takePictureIntent != null){
          intentArray = newIntent[]{takePictureIntent};
     }else{
          intentArray = newIntent[0];
     }

     IntentchooserIntent=newIntent(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, FCR);
     returntrue;
}

Create image file function, as mentioned in the above code we need this to create new temp file to upload.

private File createImageFile()throws IOException{
     @SuppressLint("SimpleDateFormat")StringtimeStamp=newSimpleDateFormat("yyyyMMdd_HHmmss").format(newDate());
     StringimageFileName="img_"+timeStamp+"_";
     FilestorageDir= Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
     return File.createTempFile(imageFileName,".jpg",storageDir);
}

Post a Comment for "Webview, File Input Field Filechooser Doesn't Show Up"