Implementing Accelerometer with Phonegap

0
2854

In this session today we will create an app using accelerometer which will respond to X ,Y and Z axis when the mobile phone is tilted in the respective angles.

  • To work on accelerometer follow the steps given below :

  1. First of all download and install the Xampp server in your machine or if it is already installed then go to Xampp -> htdocs folder and in htdocs folder create a new folder say Accelerometer .
  2. In Accelerometer folder create new file say index.html .
  3. Now open this index.html file with Notepad++ or any other text editor and write the following code :
  4. Here is the screen shot of Notepad++ window :
  5. 1
    2

  6. Now save your file and start your apache and MySQL modules from XAMPP Control Pannel.
  7. 0.1

  8. Now lets execute our app on ripple emulator .
  9. Go to emulate.phonegap.com then you will get the following window:
  10. 0.2

  11. Click on the Get Ripple Emulator button then you will be navigated to the following window :
  12. 0.3

  13. Now click on the FREE button as shown by the red arrow in the above image and you will get the following window :
  14. 0.4

  15. Now click on the ADD button and the Ripple Emulator will get added to the browser :
  16. 0.5

  17. Now open up the browser and enter the url as localhost/Accelerometer(i.e your folder name in htdocs) and enable the ripple emulator as shown in the image below :
  18. 3

  19. After clicking the enable button you will get the ripple emulator as shown below: where you have to click on the dropdown button on the left hand side as shown by the red arrow,similarly drag and rotate the mobile icon indicated by the red arrow to get the output for X , Y , Z axis:
  20. 4

  21. So as you drag and rotate the mobile icon which is located at the left handside you will get the readings at the X , Y , Z axis as shown in the image below :
  22. 5

  23. Thus we have successfully implemented accelerometer app with phonegap .

LEAVE A REPLY

Please enter your comment!
Please enter your name here