Implementing Camera API in Phonegap

0
2282

In this exercise today we will be implementing camera API in Phonegap where we will create two buttons namely Take Photo and Get Photo which will access the camera and the photogallery.

  • So to start working with the camera api follow the steps given below :

  1. Install the Xampp server in your machine and if it is already installed then go to Xampp->htdocs folder.
  2. In htdocs folder create a new folder called as Camera .
  3. In this Camera folder create an html document called as index.html
  4. Now open your index.html file in any text editor and write the following html code in it :
  5. So after writing the code you will have the following look out of your text editor :
  6. 1

  7. Now in the Camera folder create a new folder called as js .
  8. In this js folder create a new text document called as main.js i.e save it with type as js .
  9. Now open this main.js file with any text editor window and write the following code in it :
  10. Here is the screen shot of your Notepad++ window :
  11. Implementing Camera API in Phonegap2

    Implementing Camera API in Phonegap3

    Implementing Camera API in Phonegap4

  12. Hence after writing the code save your document and now sign in into your Github account by visiting github.com :
  13. 0

  14. So now enter a username ,your email id and password in the respective tabs and click on the Sign up for GitHub button .
  15. After you click on the signup button you will get the following window :
  16. Implementing Camera API in Phonegap0.1

  17. Now click on the ‘+’ icon on the right hand side as indicated by the red arrow and then click on the “ New repository ” as indicated by the blue arrow .
  18. 0.2

  19. After clicking on the New repository you will be navigated to the next window ,specify a Repository name ,select a public radio button and click on the Create repository button as shown in the image below :
  20. Implementing Camera API in Phonegap0.3

  21. So after clicking on the Create repository button you have the following window :
  22. Implementing Camera API in Phonegap0.4

  23. Go to xampp -> htdocs .
  24. In htdocs you have your Camera folder created .
  25. Now go to your start menu -> GitBash -> right click on it -> Send To -> Desktop (create a shortcut) of GitBash on Desktop as shown below :
  26. Implementing Camera API in Phonegap0.7

  27. So now on Desktop you will have a GitBash icon .
  28. Now Right Click on the GitBash icon on the desktop and go to properties and in the Start in edit box set the path as : c:xampphtdocs as shown in the image.
  29. Implementing Camera API in Phonegap0.8

  30. Now Click on Apply and OK button .
  31. Now start the GitBash application from the desktop and you will have the following screen :
  32. Implementing Camera API in Phonegap0.9

  33. Now insert the following command as shown below in the gitbash command prompt window..
  34. Thus after inserting the commands you will have the following view of your window :
  35. 0.10

  36. After you get this , insert further commands in the same command prompt window as given below :
  37. After inserting this command your gitbash command prompt window will have the following look , check whether your username and email you entered has been generated in the list :
  38. Implementing Camera API in Phonegap0.11

  39. After this insert the following commands :
  40. You will have the following window :
  41. Implementing Camera API in Phonegap0.12

  42. Now go to your github account where you had created the Camera repository and copy the add origin command and push command and paste it in the gitbash command prompt respectively.
  43. Implementing Camera API in Phonegap0.13

  44. So after adding the commands you will be asked for your github username and password ,so you will have the following window :
  45. 0.14

  46. Thus now the push operation is complete, so now we are ready to build our application .
  47. Now go to www.build.phonegap.com and click on Sign in tab present at the right.
  48. 1

  49. After clicking on the Sign in button you will get the next page where you have to click on the Sign in with GitHub button as shown by the arrow head ..
  50. 2

  51. After that you will be navigated to the next page where you have to click on the new app button as shown by the red arrow head.
  52. Implementing Camera API in Phonegap3

  53. After clicking on the new app button ,you will get the following window where you have to select the open-source tab and click on the dropdown pointer and select your app as shown in the image :
  54. 4

    NOTE : Here you will have your own application name that is the name given by you while creating the repository.

  55. When you select your app the fetching process will start as shown in the figure :
  56. 5

  57. After the fetching is complete you will get the following window :
  58. 6

  59. Now click on the Ready to Build button as shown by the red arrow in the image and you will get the following screen :
  60. 7

  61. Click on the android icon and you will have the following window popping up to save the apk file.
  62. Implementing Camera API in Phonegap8

  63. Now save your apk file and insert it in your android mobile phone and install it ,you will have the application running on your mobile phone
  64. Thus now test it on your android mobile phones .
  65. Hence we have successfully learnt implementing Camera API in Phonegap .

LEAVE A REPLY

Please enter your comment!
Please enter your name here