Android input type file

Android clicking input type=file brings up system file browser, not camera options #816

Comments

alexcroox commented Aug 21, 2019 •

Bug Report

Problem

When clicking on an html type=»file» input a system file picker appears instead of camera options.

What is expected to happen?

If I perform the same action in the system browser I get the expected dialog:

Version information

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

The text was updated successfully, but these errors were encountered:

alexcroox commented Aug 22, 2019

adityak74 commented Aug 22, 2019 •

@alexcroox
You could use cordova-plugin-camera ‘s window.navigator.camera.getPicture to trigger the right options on android. This method will let you choose your destination using https://github.com/apache/cordova-plugin-camera#cameradestinationtype—enum.

Technically add an onClick listener to your tag and handle it yourself by using the above API method, that should resolve your issue.

I guess type=»file» is more generic and hence they handle it by showing a system file picker.

Читайте также:  Экран андроид бмв е90

xyozio commented Aug 27, 2019 •

The implementation of openFileChooser function is very simple and doesn’t handle capture:

Lines 235 to 249 in 2163c8a

public void openFileChooser ( final ValueCallback Uri > uploadMsg , String acceptType , String capture )
<
Intent intent = new Intent ( Intent . ACTION_GET_CONTENT );
intent . addCategory( Intent . CATEGORY_OPENABLE );
intent . setType( » */* » );
parentEngine . cordova . startActivityForResult( new CordovaPlugin () <
@Override
public void onActivityResult ( int requestCode , int resultCode , Intent intent ) <
Uri result = intent == null || resultCode != Activity . RESULT_OK ? null : intent . getData();
LOG . d( LOG_TAG , » Receive file chooser URL: » + result);
uploadMsg . onReceiveValue(result);
>
>, intent, FILECHOOSER_RESULTCODE );
>

xyozio commented Aug 27, 2019

In XWalk this function got more attention:

Unfortunatelly XWalk is not developed anymore so you can either use the last version of XWalk, use the cordova-camera plugin or try and submit a PR that improves the openFileChooser function.

adityak74 commented Aug 27, 2019 •

I think you can submit a PR if you want to translate the HTML Image element’s accept property into intent type for the openFileChooser method.

jalixdesign commented Sep 19, 2019

I currently have the same problem.
Unfortunately, I have no Java / Android skills, so I could extend the function myself.

Is there someone who can extend the function?

biodiv commented Nov 6, 2019

I agree that this is a problem. It should be handled according to the W3C recommendations, like the system browser does.

biodiv commented Nov 7, 2019 •

You could use cordova-plugin-camera ‘s window.navigator.camera.getPicture to trigger the right options on android. This method will let you choose your destination using https://github.com/apache/cordova-plugin-camera#cameradestinationtype—enum.

Technically add an onClick listener to your tag and handle it yourself by using the above API method, that should resolve your issue.

Читайте также:  Как планшет лучше андроид или виндовс

This approach works but has limitations. For example, .files is a FileList instance, which does not offer a push method (like regular Arrays) for good reasons. So, you cannot retrieve a File using the camera plugin and simply append it to .files using javascript. You have to implement your own form/file handling if you use the camera plugin.

Источник

Оцените статью