gpt4 book ai didi

java - 如何在 GWT 中通过 Property Provider 获取 Android 版本?

转载 作者:行者123 更新时间:2023-11-30 02:57:28 26 4
gpt4 key购买 nike

我想检测用户浏览器是来自 IOS、Android 还是其他任何浏览器,我还想检测 android 版本。

我想我可以像这样在我的 gwt.xml 文件中使用属性提供程序来做到这一点:

<define-property name="mobile.user.agent" values="android, iphone, not_mobile" />
<property-provider name="mobile.user.agent"><![CDATA[
{
var ua = window.navigator.userAgent.toLowerCase();
if (ua.indexOf('android') != -1) { return 'android'; }
if (ua.indexOf('iphone') != -1) { return 'iphone'; }
return 'not_mobile';
}
]]></property-provider>

<!-- Constrain the value for non-webkit browsers -->
<set-property name="mobile.user.agent" value="not_mobile" >
<none> <!-- Actually means NOR, in this case "not safari" -->
<when-property-is name="user.agent" value="safari" />
</none>
</set-property>

来源:https://code.google.com/p/google-web-toolkit/wiki/ConditionalProperties

有没有办法检测用户设备的 Android 版本?

最佳答案

您可以使用 JSNI:

public static final native double getAndroidVersion() /*-{
var ua = $wnd.navigator.userAgent;
var match = ua.match(/Android (\d+(?:\.\d+)+);/);
return match = match ? match[1] : 0;
}-*/;

关于java - 如何在 GWT 中通过 Property Provider 获取 Android 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23038388/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com