Apache Cordova
  1. Apache Cordova
  2. CB-753

ER: API to query if device has a camera

    Details

    • Type: New Feature New Feature
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Duplicate
    • Affects Version/s: 1.7.0
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      Cordova does not offer any API to query the device for its capabilities, so one cannot know if it has a camera with which to take a picture without attempting to take a picture, falling through the error handler and then hard-match the error code – a pretty poor user experience. i have seen some suggestion to check device.camera, but a device may still have a library to pull an image from while not having a camera, so that isn't likely helpful. there isn't even any way to find the specific hardware revision to match off that.

        Issue Links

          Activity

          Hide
          Julien Bouquillon added a comment -

          +1 on this. any W3C spec for capabilities definition/discovery ?

          Show
          Julien Bouquillon added a comment - +1 on this. any W3C spec for capabilities definition/discovery ?
          Hide
          Filip Maj added a comment -

          There was a System Information API that the DAP worked on, and it had an API with which you could check input devices. This spec has since been shelved by the W3C

          Even the latest getUserMedia spec has no way to first query for the existence of a camera or input device. In all of the W3C specs, you have to go through the motions of attempting to get the media first, parse errors, etc.

          Perhaps we could add it to the navigator.camera API since that is our own home grown API. I will post about it on the dev mailing list and see what's up. I would recommend you guys sign up for the mailing list and make your case / support the API extension on there as well.

          Show
          Filip Maj added a comment - There was a System Information API that the DAP worked on, and it had an API with which you could check input devices . This spec has since been shelved by the W3C Even the latest getUserMedia spec has no way to first query for the existence of a camera or input device. In all of the W3C specs, you have to go through the motions of attempting to get the media first, parse errors, etc. Perhaps we could add it to the navigator.camera API since that is our own home grown API. I will post about it on the dev mailing list and see what's up. I would recommend you guys sign up for the mailing list and make your case / support the API extension on there as well.
          Hide
          Brian LeRoux added a comment -

          I put a note in teh wiki to have a look at this post 2.x ---some prior art out there but not much. Its a tricky thing to impl so it def should come after the plugins stuff is documented and tooled.

          http://lists.w3.org/Archives/Public/public-webrtc/2012Jan/0041.html

          Show
          Brian LeRoux added a comment - I put a note in teh wiki to have a look at this post 2.x ---some prior art out there but not much. Its a tricky thing to impl so it def should come after the plugins stuff is documented and tooled. http://lists.w3.org/Archives/Public/public-webrtc/2012Jan/0041.html
          Hide
          Jonathan Bond added a comment -

          Agree that it would be nice for Cordova to fill this 'gap', native platforms allow to check this:

          http://stackoverflow.com/questions/7736973/check-camera-existence-in-ios-pho
          negap
          http://stackoverflow.com/questions/12976725/checking-for-camera-access-in-ph
          onegap?lq=1

          If could likely be added int two ways:

          • navigator.camera.isAvailable()
          • device.hasFeature('camera');
          Show
          Jonathan Bond added a comment - Agree that it would be nice for Cordova to fill this 'gap', native platforms allow to check this: http://stackoverflow.com/questions/7736973/check-camera-existence-in-ios-pho negap http://stackoverflow.com/questions/12976725/checking-for-camera-access-in-ph onegap?lq=1 If could likely be added int two ways: navigator.camera.isAvailable() device.hasFeature('camera');
          Hide
          Shazron Abdullah added a comment -

          We had some discussion on this in the mailing list: http://markmail.org/thread/lt25iqwkb55oxzgu

          Show
          Shazron Abdullah added a comment - We had some discussion on this in the mailing list: http://markmail.org/thread/lt25iqwkb55oxzgu
          Hide
          Jonathan Bond added a comment -

          Thanks, some more thoughts:

          I image that window.device.capabilities = {} would be initially an empty object?

          Then the camera plugin when/if loaded would set:

          window.device.capabilities.camera =

          {front: true, back: false}

          ;
          window.device.capabilities.frontCamera = true;
          window.device.capabilities.backCamera = true;

          I'd also propose a 'shortcut' (sugar function): window.device.has('camera') , window.device.has('frontCamera')

          Show
          Jonathan Bond added a comment - Thanks, some more thoughts: I image that window.device.capabilities = {} would be initially an empty object? Then the camera plugin when/if loaded would set: window.device.capabilities.camera = {front: true, back: false} ; window.device.capabilities.frontCamera = true; window.device.capabilities.backCamera = true; I'd also propose a 'shortcut' (sugar function): window.device.has('camera') , window.device.has('frontCamera')
          Hide
          Jonathan Bond added a comment -

          Small clarification, the purpose of device.has() or device.hasCapability() would be to always return a boolean value:

          window.device.has = function(feature)

          { return this.capabilities[feature]) ? true : false }

          Plugins could extend window.device.capabilities with additional information about the device.

          Show
          Jonathan Bond added a comment - Small clarification, the purpose of device.has() or device.hasCapability() would be to always return a boolean value: window.device.has = function(feature) { return this.capabilities[feature]) ? true : false } Plugins could extend window.device.capabilities with additional information about the device.
          Hide
          Filip Maj added a comment -

          Device capabilities API being discussed in CB-1696, so closing this as a duplicate.

          Show
          Filip Maj added a comment - Device capabilities API being discussed in CB-1696 , so closing this as a duplicate.

            People

            • Assignee:
              Unassigned
              Reporter:
              Jean-Pierre
            • Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development