I've discovered, and confirmed by working with Microsoft support, that the Camera.AvailableDevices property does not work when using the Windows 10 App. Instead of returning a table containing the Id and Name information for the cameras available on the system it instead returns a collection of zero length.
I have developed an app that we are using for employees, guests and visitors to check in, answer health questions, and take their picture. My app uses the AvailableDevices property to collect camera information so that I can provide a button that will cycle through the available cameras on a device. This allows those using the app on mobile devices to switch between front and rear-facing cameras, for example.
The app works as expected when using a web browser or the mobile apps, but not when using the W10 App.
One place this app runs is on a Surface tablet. On this device, specifically, I'd rather use the W10 App instead of a web browser to run my application because using a web browser requires re-authentication every 8 hours and the W10 App does not. This is run continuously and re-authentication is a burden. Currently, I'm currently using one version of the app that runs on the Surface, hard-coded to use it's front-facing camera. I have another version that users can use on their mobile devices where it's much more important that they can switch between available cameras before taking a picture. Maintaining and updating two versions of the app is not ideal.
This leads me to the point of this post. Microsoft support stated that while this is a known bug there is no plan to address it any time soon. They stated that there are some users relying on the W10 app returning this zero length collection (?!) and changing the behavior of the AvailableDevices property on the W10 app would be a breaking change. This behavior might be changed in a major update to the W10 App but there is no timeline and no guarantee that this would even happen. The only "workaround" they provided was to use Edge, or another browser, which, at least for my use case, is not ideal.
Their only other suggestion was to post, here. Perhaps there is someone out there with another idea? Or maybe there are enough people frustrated with this not working that can respond here that Microsoft will see that there is, indeed, interest in fixing this bug?
I did a little testing and here is what I found.
1) if you set the Camera property of the Camera control to point to a variable and change the value of the variable you can change the camera from front '0', to back '1'.
2) Additional USB cameras can change the numbering. Front '0', External '1', Back '2'.
2) The camera won't actually refresh until you go to another screen and come back
3) You are correct that the availableDevices array is blank when in the Windows 10 App.
If would be nice to have access to the availableDevices to know how many cameras there are and which one is which. But you can create a button that will switch between cameras, even in the Windows 10 client. I would implement the switch on a settings screen. That way after you change the camera and exit the screen the control will update.
Not a perfect solution but it could work.
I am so sorry you are inconvenienced by the lack of features.
Perhaps the engineer has directed you to the following site
This site is for users to submit feature requests.
MS developers refer to it and consider adding features to it, such as features that have a lot of votes.
Please feel free to submit your feature requests.
<Power Apps Community > Ideas>
@Pstork1 Thank you for the informed response! I am, indeed, doing what you suggest - assigning the Camera property of the Camera control to a variable. That variable is incremented by a button, up to the maximum number of devices (-1) returned by the AvailableDevices property, at which point it resets back to 0. This works great when I get valid data from the AvailableDevices property.
When using the W10 App, where that property does not return valid data, I could test for AvailableDevices having a length of zero, and if so set my maximum number of devices to some arbitrary value. However, how am I to know if this means there are no cameras on the device the app is being run on? If that's the case, there are no available devices, then I want to present the user with an error screen stating that the app requires a camera. This is the functionality I have implemented when I can query AvailableDevices.
I did think about just setting a maximum device value of, say 5, and then letting the users cycle through whatever cameras are valid but that presents a pretty poor user experience with the app displaying the message "Your camera isn't set up, or you're already using it." as the Camera control will do when the Camera property is set to an invalid value. I'd much rather the users not even reach a screen with the camera control if there is no valid camera available.
An option that I came up with that I've not had time to fully implement yet is to cycle that variable through the values 0-5 and use Camera.OnStream to capture an image. I believe I can test to see if an image was captured and, if so, know that the camera id is valid. This is obviously a kludge but should work on the W10 App. Perhaps I only implement this logic if the AvailableDevices property returns a zero length collection? Is there any way to know the app is running on the Win10 App instead of another platform? This would all be so much easier if the AvailableDevices property just worked!
Anyway, thank you for your response. I might have some time later to work on implementing my camera testing using .OnStream. If so, I'll follow up here.
Cycling through to grab an image may not work as well as you would think. You'll also get distorted images from the IR camera and any camera recording apps you have loaded on the tablet. You are probably better off just setting the max camera to ❤️ and letting the user change. Its not optimal I agree, but I don't think there is currently a better workaround.
Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.
Featuring samples like Return to the Workplace and Emergency Response Applications
Features releasing from October 2020 through March 2021