如何在webview中为手机和平板电脑提供两个链接?

Sha*_*dow 4 android android-widget android-intent android-layout

我有两个链接,例如:说facebook.com和m.facebook.com.如果是Android手机,我想

打开m.facebook.com.如果是Android平板电脑,我想打开facebook.com链接.我想做的

webview.怎么可能?

Pra*_*rma 5

这是使用以下的另一种解决方案simple flag:

在say(res/values-xlarge/)中的特定值文件中设置一个布尔值:

<resources>
    <bool name="isTabletDevice">true</bool>
</resources>
Run Code Online (Sandbox Code Playgroud)

然后,在像say(res/values/)这样的"标准"值文件中:

<resources>
    <bool name="isTabletDevice">false</bool>
</resources>
Run Code Online (Sandbox Code Playgroud)

然后从你的activity,获取此flag value检查device type:

boolean tabletDeviceSize = getResources().getBoolean(R.bool.isTabletDevice);
if (tabletDeviceSize) {
    //use tablet link
} else {
    //use mobile link
}
Run Code Online (Sandbox Code Playgroud)

谢谢.