kortgat commented on issue #816:
URL: https://github.com/apache/cordova-android/issues/816#issuecomment-834181505


   what I did (which is still in progress since im learning android Java for 
this) is to modify the onShowFileChooser() method of 
"platforms\android\CordovaLib\src\org\apache\cordova\engine\SystemWebChromeClient.java"
   
   add import:
   import android.provider.MediaStore;
   
   and changed the method to below:
   ```
    public boolean onShowFileChooser(WebView webView, final 
ValueCallback<Uri[]> filePathsCallback, final WebChromeClient.FileChooserParams 
fileChooserParams) {
           // Check if multiple-select is specified
           LOG.d(LOG_TAG, "file chooser opened");
           Boolean selectMultiple = false;
           if (fileChooserParams.getMode() == 
WebChromeClient.FileChooserParams.MODE_OPEN_MULTIPLE) {
               selectMultiple = true;
           }
           String[] acceptTypes = fileChooserParams.getAcceptTypes(); 
           LOG.d(LOG_TAG,"File types: "+ toCSV(acceptTypes));
           Intent intent =  fileChooserParams.createIntent();
           intent.addCategory(Intent.CATEGORY_OPENABLE); 
           intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, selectMultiple);
           
           // Uses Intent.EXTRA_MIME_TYPES to pass multiple mime types.
           if (acceptTypes.length > 1) {
               intent.setType("*/*"); // Accept all, filter mime types by 
Intent.EXTRA_MIME_TYPES.
               intent.putExtra(Intent.EXTRA_MIME_TYPES, acceptTypes);
           }
           
           Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
   
           Intent GalleryIntent = new 
Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
   
           try {
               Intent chooserIntent;
   
                   chooserIntent = Intent.createChooser(intent, "Open file");
                   chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new 
Intent[]{GalleryIntent,cameraIntent, intent});
      
               parentEngine.cordova.startActivityForResult(new CordovaPlugin() {
                   @Override
                   public void onActivityResult(int requestCode, int 
resultCode, Intent intent) {
                       Uri[] result = null;
                       if (resultCode ==  Activity.RESULT_OK && intent != null) 
{
                           if (intent.getClipData() != null) {
                               // handle multiple-selected files
                               final int numSelectedFiles = 
intent.getClipData().getItemCount();
                               result = new Uri[numSelectedFiles];
                               for (int i = 0; i < numSelectedFiles; i++) {
                                   result[i] = 
intent.getClipData().getItemAt(i).getUri();
                                   LOG.d(LOG_TAG, "Receive file chooser URL: " 
+ result[i]);
                               }
                           }
                           else if (intent.getData() != null) {
                               // handle single-selected file
                               result = 
WebChromeClient.FileChooserParams.parseResult(resultCode, intent);
                               LOG.d(LOG_TAG, "Receive file chooser URL: " + 
result);
                           }
                       }
                       filePathsCallback.onReceiveValue(result);
                   }
               }, chooserIntent, FILECHOOSER_RESULTCODE);
           } catch (ActivityNotFoundException e) {
               LOG.w("No activity found to handle file chooser intent.", e);
               filePathsCallback.onReceiveValue(null);
           }
           return true;
       }
   ```
   
   I still need to figure out how to unbundle the gallery options but atleast 
it works for now


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to