title: Open Filechooser after Permission Granted in Android
body: <p>I am using the following code to check if camera &amp; storage permissions have been granted when user clicks on input-file field on my website in android webview: </p>
  
  <pre><code> public boolean file_permission(){
           if(Build.VERSION.SDK_INT &gt;=23 &amp;&amp; (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)) {
  
              ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA}, 1);
  
              return false;
          }else{
              return true;
          }
      }
  
    class MyWebChromeClient extends WebChromeClient {
  
              // Handling onshow file chooser
              @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
              public boolean onShowFileChooser(WebView webView, ValueCallback&lt;Uri[]&gt; filePathCallback, FileChooserParams fileChooserParams) {
  
                  if(file_permission() &amp;&amp; Build.VERSION.SDK_INT &gt;= 21) {
  
                      file_path = filePathCallback;
                      Intent takePictureIntent = null;
  
                          takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                          if (takePictureIntent.resolveActivity(MainActivity.this.getPackageManager()) != null) {
                              File photoFile = null;
                              try {
                                  photoFile = create_image();
                                  takePictureIntent.putExtra("PhotoPath", cam_file_data);
                              } catch (IOException ex) {
                                  Log.e(TAG, "Image file creation failed", ex);
                              }
                              if (photoFile != null) {
                                  cam_file_data = "file:" + photoFile.getAbsolutePath();
                                  takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
                              } else {
                                  cam_file_data = null;
                                  takePictureIntent = null;
                              }
                          }
  
                      Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
                      contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
                      contentSelectionIntent.setType(file_type);
  
                      Intent[] intentArray;
  
                      intentArray = new Intent[]{takePictureIntent};
  
                      Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
                      chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
                      chooserIntent.putExtra(Intent.EXTRA_TITLE, "Select Photo for yourPrint");
                      chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
                      startActivityForResult(chooserIntent, file_req_code);
                      return true;
  
                  }  else {
                      return false;
                  }
              }
          }
  </code></pre>
  
  <p>When the permission is checked via <code>file_permission()</code>, the accept permission dialog appears. But once the user accepts the permission, the input-file field needs to be clicked again by the user to show the file chooser. I want the input-field that originally triggered the <code>onShowFileChooser</code> to be clicked again automatically after user accepts the permissions, so that file chooser opens automatically. </p>
  
  <p>I have tried using <code>onRequestPermissionsResult</code> with javascript to trigger click on input field after permissions acceptance using this code <code>javascript:jQuery('.file-input-field').trigger('click')</code>, However, I do not want to use this way as chrome blocks programmatic clicks on input fields with type file for security purposes. </p>
  
  <p>How to accomplish this?</p>