How to modify file selector options in a webview?











up vote
0
down vote

favorite












In my application, I'm using a webview page in which users can select files to upload. It's only showing two options for Camera and Documents. But in google chrome or even other webview applications, there are more options, such as voice recorder.



I'm using WebChromeClient as base for my pages. I used the startActivityOpenChooser before file opener prompt, which I believe this function is all I need to change, if possible.



// openFileChooser for Android < 3.0
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
openFileChooser(uploadMsg, "");
}
...
public void startActivityOpenChooser(String acceptType){
File imageStorageDir = new File(mainActivity.getExternalCacheDir(), "user_upload_files");

if (!imageStorageDir.exists()) {
// Create user_upload_files at sdcard
imageStorageDir.mkdirs();
}

// Create camera captured image file path and name
File file = new File(imageStorageDir + File.separator + "IMG_" + String.valueOf(System.currentTimeMillis()) + ".jpg");
mainActivity.mCapturedImageURI = Uri.fromFile(file);

// Camera capture image intent
final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mainActivity.mCapturedImageURI);

Intent i = null;
if (Build.VERSION.SDK_INT < 19) {
i = new Intent();
i.setAction(Intent.ACTION_GET_CONTENT);
} else {
i = new Intent(Intent.ACTION_OPEN_DOCUMENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
}
i.setType("*/*");

// Create file chooser intent
Intent chooserIntent = Intent.createChooser(i, mainActivity.getResources().getString(R.string.choose_file_for_upload));

// Set camera intent to file chooser
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Parcelable{captureIntent});

// On select image call onActivityResult method of activity
mainActivity.startActivityForResult(chooserIntent, MainActivity.FILECHOOSER_RESULTCODE);
}


Here is an image showing the difference: IMG










share|improve this question




























    up vote
    0
    down vote

    favorite












    In my application, I'm using a webview page in which users can select files to upload. It's only showing two options for Camera and Documents. But in google chrome or even other webview applications, there are more options, such as voice recorder.



    I'm using WebChromeClient as base for my pages. I used the startActivityOpenChooser before file opener prompt, which I believe this function is all I need to change, if possible.



    // openFileChooser for Android < 3.0
    public void openFileChooser(ValueCallback<Uri> uploadMsg) {
    openFileChooser(uploadMsg, "");
    }
    ...
    public void startActivityOpenChooser(String acceptType){
    File imageStorageDir = new File(mainActivity.getExternalCacheDir(), "user_upload_files");

    if (!imageStorageDir.exists()) {
    // Create user_upload_files at sdcard
    imageStorageDir.mkdirs();
    }

    // Create camera captured image file path and name
    File file = new File(imageStorageDir + File.separator + "IMG_" + String.valueOf(System.currentTimeMillis()) + ".jpg");
    mainActivity.mCapturedImageURI = Uri.fromFile(file);

    // Camera capture image intent
    final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mainActivity.mCapturedImageURI);

    Intent i = null;
    if (Build.VERSION.SDK_INT < 19) {
    i = new Intent();
    i.setAction(Intent.ACTION_GET_CONTENT);
    } else {
    i = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    i.addCategory(Intent.CATEGORY_OPENABLE);
    }
    i.setType("*/*");

    // Create file chooser intent
    Intent chooserIntent = Intent.createChooser(i, mainActivity.getResources().getString(R.string.choose_file_for_upload));

    // Set camera intent to file chooser
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Parcelable{captureIntent});

    // On select image call onActivityResult method of activity
    mainActivity.startActivityForResult(chooserIntent, MainActivity.FILECHOOSER_RESULTCODE);
    }


    Here is an image showing the difference: IMG










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      In my application, I'm using a webview page in which users can select files to upload. It's only showing two options for Camera and Documents. But in google chrome or even other webview applications, there are more options, such as voice recorder.



      I'm using WebChromeClient as base for my pages. I used the startActivityOpenChooser before file opener prompt, which I believe this function is all I need to change, if possible.



      // openFileChooser for Android < 3.0
      public void openFileChooser(ValueCallback<Uri> uploadMsg) {
      openFileChooser(uploadMsg, "");
      }
      ...
      public void startActivityOpenChooser(String acceptType){
      File imageStorageDir = new File(mainActivity.getExternalCacheDir(), "user_upload_files");

      if (!imageStorageDir.exists()) {
      // Create user_upload_files at sdcard
      imageStorageDir.mkdirs();
      }

      // Create camera captured image file path and name
      File file = new File(imageStorageDir + File.separator + "IMG_" + String.valueOf(System.currentTimeMillis()) + ".jpg");
      mainActivity.mCapturedImageURI = Uri.fromFile(file);

      // Camera capture image intent
      final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
      captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mainActivity.mCapturedImageURI);

      Intent i = null;
      if (Build.VERSION.SDK_INT < 19) {
      i = new Intent();
      i.setAction(Intent.ACTION_GET_CONTENT);
      } else {
      i = new Intent(Intent.ACTION_OPEN_DOCUMENT);
      i.addCategory(Intent.CATEGORY_OPENABLE);
      }
      i.setType("*/*");

      // Create file chooser intent
      Intent chooserIntent = Intent.createChooser(i, mainActivity.getResources().getString(R.string.choose_file_for_upload));

      // Set camera intent to file chooser
      chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Parcelable{captureIntent});

      // On select image call onActivityResult method of activity
      mainActivity.startActivityForResult(chooserIntent, MainActivity.FILECHOOSER_RESULTCODE);
      }


      Here is an image showing the difference: IMG










      share|improve this question















      In my application, I'm using a webview page in which users can select files to upload. It's only showing two options for Camera and Documents. But in google chrome or even other webview applications, there are more options, such as voice recorder.



      I'm using WebChromeClient as base for my pages. I used the startActivityOpenChooser before file opener prompt, which I believe this function is all I need to change, if possible.



      // openFileChooser for Android < 3.0
      public void openFileChooser(ValueCallback<Uri> uploadMsg) {
      openFileChooser(uploadMsg, "");
      }
      ...
      public void startActivityOpenChooser(String acceptType){
      File imageStorageDir = new File(mainActivity.getExternalCacheDir(), "user_upload_files");

      if (!imageStorageDir.exists()) {
      // Create user_upload_files at sdcard
      imageStorageDir.mkdirs();
      }

      // Create camera captured image file path and name
      File file = new File(imageStorageDir + File.separator + "IMG_" + String.valueOf(System.currentTimeMillis()) + ".jpg");
      mainActivity.mCapturedImageURI = Uri.fromFile(file);

      // Camera capture image intent
      final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
      captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mainActivity.mCapturedImageURI);

      Intent i = null;
      if (Build.VERSION.SDK_INT < 19) {
      i = new Intent();
      i.setAction(Intent.ACTION_GET_CONTENT);
      } else {
      i = new Intent(Intent.ACTION_OPEN_DOCUMENT);
      i.addCategory(Intent.CATEGORY_OPENABLE);
      }
      i.setType("*/*");

      // Create file chooser intent
      Intent chooserIntent = Intent.createChooser(i, mainActivity.getResources().getString(R.string.choose_file_for_upload));

      // Set camera intent to file chooser
      chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Parcelable{captureIntent});

      // On select image call onActivityResult method of activity
      mainActivity.startActivityForResult(chooserIntent, MainActivity.FILECHOOSER_RESULTCODE);
      }


      Here is an image showing the difference: IMG







      java android android-webview google-chrome-webview






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 11:53









      Kling Klang

      32.3k156288




      32.3k156288










      asked Nov 10 at 10:25









      Mᴏʀᴀᴅɴᴇᴊᴀᴅ

      59711029




      59711029





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238008%2fhow-to-modify-file-selector-options-in-a-webview%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238008%2fhow-to-modify-file-selector-options-in-a-webview%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Schultheiß

          Verwaltungsgliederung Dänemarks

          Liste der Kulturdenkmale in Wilsdruff