How to call Ajax based on phone vibration?

I am trying to make my first web application for mobile devices. Is it possible to capture the “shaking event” on the android?

I was looking for a jquery moble library, but there were no jarring events or an accelerometer.

Is it possible to have an Ajax call based on a shake event?

Thanks Arman.

+4
source share
4 answers

A person, maybe the plugin could do this, but only with JqueryMobile I think that you can not get the shake event.

Here's a list of jquery events: http://jquerymobile.com/demos/1.0a2/experiments/api-viewer/index.html

+3
source

shake.js provides support for the shake event, which should facilitate the implementation of the desired functions:

https://github.com/alexgibson/shake.js

+3
source

(Android)

You can script the "event proxy" that runs onLoad by adding the Javascript interface to your WebView, here is some pseudo code:

[...] mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setDomStorageEnabled(true); mWebView.addJavascriptInterface(new JavaScriptInterface(), "android"); mWebView.loadUrl("file:///android_asset/www/index.html"); } final class JavaScriptInterface { JavaScriptInterface () { } public void startEventProxy() { // capture and pass shake events to javascript } } 

(iPhone)

You can interact with the Device Motion API available in Safari Mobile.

http://plugins.jquery.com/project/tilt

+2
source

I am not an expert in this, but I do not think that you have access to the accelerometer, compass and other "local" events through a mobile browser. If you want to create a local application with javasrcipt, css and HTML, you can look at phonegap , titanium or rhodes .

EDITOR: Rhodes for the ruby. It looks like a ruby ​​on rails. This way you use ruby, javascript, HTML and css.

Then you will get access to all the events you want.

Read this for more information. Cross-platform mobile app development challenge: PhoneGap vs. Titanium vs. Rhodes

+1
source

Source: https://habr.com/ru/post/1337322/


All Articles