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 ParcelablecaptureIntent);

// 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 ParcelablecaptureIntent);

    // 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 ParcelablecaptureIntent);

      // 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 ParcelablecaptureIntent);

      // 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

      32k156286




      32k156286










      asked Nov 10 at 10:25









      ananda

      4741929




      4741929



























          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



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















           

          draft saved


          draft discarded















































           


          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














































































          Popular posts from this blog

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          ReactJS Fetched API data displays live - need Data displayed static

          Evgeni Malkin