【发布时间】:2013-01-02 08:05:49
【问题描述】:
我有两个链接,例如:说 facebook.com 和 m.facebook.com。如果是 android 手机,我想
打开m.facebook.com。如果是安卓平板,我想打开facebook.com链接。我想在里面做
webview.怎么可能?
【问题讨论】:
标签: android android-layout android-intent android-widget
我有两个链接,例如:说 facebook.com 和 m.facebook.com。如果是 android 手机,我想
打开m.facebook.com。如果是安卓平板,我想打开facebook.com链接。我想在里面做
webview.怎么可能?
【问题讨论】:
标签: android android-layout android-intent android-widget
这是另一个使用simple flag的解决方案:
在特定值文件中设置一个布尔值,例如say (res/values-xlarge/):
<resources>
<bool name="isTabletDevice">true</bool>
</resources>
然后,在“标准”值文件中,比如说 (res/values/):
<resources>
<bool name="isTabletDevice">false</bool>
</resources>
然后从您的activity 获取此flag value 以检查device type:
boolean tabletDeviceSize = getResources().getBoolean(R.bool.isTabletDevice);
if (tabletDeviceSize) {
//use tablet link
} else {
//use mobile link
}
谢谢。
【讨论】:
试试这个可能对你有帮助。
public static boolean isTablet(Context context) {
boolean xlarge = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 4);
boolean large = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE);
return (xlarge || large);
}
if(isTablet(context)) {
//use tablet link
}
else {
//use mobile link.
}
【讨论】: