开发者

How to invoke Ajax based on phone shake?

I am trying to make my first web application f开发者_运维技巧or mobile devices. Is it possible to capture the "shake event" on android?

I was looking on jquery moble library but there is no shake event or accelerometer events.

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

Thanks Arman.


Man, maybe a plugin could do that, but only with JqueryMobile I think you won't be able to get the shake event.

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


shake.js provides support for a shake event that should make it easy to implement the desired functionality:

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


(Android)

You could script an "event proxy" that is started onLoad by attaching a Javascript interface to your WebView, here's some pseudocode:

    [...]

    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 interface with the Device Motion API, available in Safari Mobile.

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


I am not an expert on this, but I do not think you have access to accelerometer, compass and other "local" events trough the mobile browser. If you want to make an local app with javasrcipt, css and HTML, you can look into phonegap, titanium or rhodes.

EDIT: Rhodes is for ruby. It similar to ruby on rails. So you use ruby, javascript, HTML and css.

Then you'll have access to all the events you want.

Read this for more info Mobile Apps cross-platform development challenge: PhoneGap vs. Titanium vs. Rhodes

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜