Ionic: How to turn on camera

I want to write code that turn on my web camera and mobile camera and capture photo and save photo in database. I read this article http://learn.ionicframework.com/formulas/cordova-camera/ and write same code. Take Photo button is avaliable but its not turning my camera on ! I use " ionic run android " command to run this application on android cellphone but this also doesn’t work on android cellphone. How to turn on camera to take photo. Can anyone please help me!

The camera won’t work unless it is running on a device (it won’t trigger your webcam when running on desktop). As you mentioned though you’ve tried it on an Android which should work. I’ve written a tutorial on how to use the Camera plugin with Ionic using ngCordova here: http://www.joshmorony.com/store-camera-photos-permanently-using-phonegap-ionic-ngcordova/ if you need a little more guidance.

1 Like

Thanks @joshmorony ! :blush:

Ionic apps are for cellphones only they will not work on Desktop Systems ?

HTML5 mobile frameworks like Ionic in general do work on desktop as well. Ionic will work on desktop but it is specifically designed for iOS / Android.

The problem with desktop is that you can’t use any Cordova plugins (like the Camera plugin). The Cordova plugins won’t be available until you compile with Cordova and install on a device. If you don’t want access to any native plugins then it will run on mobile / desktop fine. (btw, although typically a plugin is used to access the native Camera API, it is also possible to access the camera through plain HTML5, check this out: http://www.html5rocks.com/en/tutorials/getusermedia/intro/)

Its great !
Thanks a lot @joshmorony :blush:

If you are testing your app in the Android simulator and not the browser, you can access the camera and use it in your local testing.

You mention that you are running ‘ionic run android’, this suggests you are using the simulator and not testing in the browser?

If so, in Android you can turn the camera on when setting up the simulator. For testing, I use local storage. I have a webcam installed on my PC. Then when you run your app in the simulator you can access the camera and use it in your app.