我想將加速度值從js傳遞給java。誰能告訴我哪裏錯了?如何將JS代碼中的值傳遞給Java中的JSNI
這裏是我的代碼:
public class Accelerometer extends JavaScriptObject {
protected Accelerometer(){};
public static native double getCurrentAccelerationX() /*-{
var x = 0.0;
$wnd.ondevicemotion = function(event){
//$wnd.alert(event.accelerationIncludingGravity.x);
x = event.accelerationIncludingGravity.y;
};
return x;
}-*/;
}
看到[這篇文章](http://stackoverflow.com/questions/9584991/how-to-instantiate-a-java-class-from-within-jsni)。 – 2012-08-15 09:44:26