繁体   English   中英

Android 5上的HTML 5中的设备方向问题

[英]device orientation problem in HTML 5 on Android

我有以下代码来检查HTML 5中的设备方向和设备运动处理。我是从http://dev.w3.org/geo/api/spec-source-orientation.html获得的 我使用iPhone3G测试了我的代码,并捕获了运动事件。 我不知道为什么设备方向没有被限制。 我相信,由于iPhone3G不具有Compass支持,因此我无法捕获“ compassneedscalibration”事件。

我在Android浏览器中测试了该应用。 (HTC Wildfire)。 我没有任何事件。 请分享您为什么我们无法在Android Mobile中获得活动?

 window.addEventListener("compassneedscalibration", function(event) {
                  alert('Your compass needs calibrating! Wave your device in a figure-eight motion');
                  event.preventDefault();


     }, true);

    window.addEventListener("deviceorientation", function(event) {
                  // process event.alpha, event.beta and event.gamma
                  alert("deviceorientation");
    }, true);

    window.addEventListener("devicemotion", function(event) {
                  // Process event.acceleration, event.accelerationIncludingGravity,
                  // event.rotationRate and event.interval
                   alert("devicemotion");
    }, true);

更新1

我在iPhone和iPad上进行测试时注意到的一件事是,设备是否移动,事件是否一直持续触发而没有任何停止。

更新2

我发现了我在UPDATE 1中提出的问题背后的原因。 该API似乎每秒检测和发送加速度计数据50次。

我知道现在这些功能仅在iOS Safari浏览器中实现。 因此,我们无法在iOS中捕获这些事件。

消息来源: http//www.mobilexweb.com/samples/ball.html

尝试改为监听Android中的“调整大小”事件。 如果您使用的是jQuery,则您的代码可能如下所示:

$(window).bind('resize', function() {
    alert('resize!');
});

在iOS上,您需要捕获的事件是“ onorientationchange”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM