Reputation: 853
I am using ionic native camera plugin similar to this blog. When I build android apk and install it in mobile camera plugin is working as expected. But If I deploy same to firebase hosting and testing by opening it in mobile browser - I am unable to open camera.
How can I make it work in mobile browser?
Upvotes: 2
Views: 2477
Reputation: 7507
Cordova plugins do not work in the browser if you use ionic-serve
to build your project. Cordova is platform based which means if a plugin developer creates a plugin he needs to add code for every platform he wants to support. In many cases also the Browser
platform is supported. To make sure you can always check in plugin.xml
of the plugin you want to use: Search for the following tag: <platform name="browser">
.
To add the browser platform:
ionic cordova platform add browser
And then to build/run it for production:
ionic cordova run browser --prod
You can find the code you need to deploy to your webserver in the platforms/browser/www
folder.
Here you can find the code the camera plugin uses to take a picture when deployed via the browser platform.
Upvotes: 1
Reputation: 65938
You cannot do that with native camera plugin. To use that you must use a device. Because it designed for using device's native camera. In other words, Cordova Plugins use native device code (Swift, JAVA) to perform their functions.
How can I make it work in a mobile browser?
If you're developing PWA (Progressive Web Apps)
then you can use service workers to access the camera on the device. Here you can see What Web Can Do Today.
Note: But you cannot use any Cordova plugins with PWA apps.
Chrome Version 60.0.3112.113
Upvotes: 2