如何编程方式确定的Android目标设备? [英] How to determine the target device programmatically in Android?
本文介绍了如何编程方式确定的Android目标设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想以编程方式确定(在Android平台上),如果目标设备是手机或平板电脑。
有没有办法做到这一点?
我试着使用密度指标,以确定相应的分辨率和使用的资源(图片和布局),但它并没有变成好。还有,当我发动对电话(Droid X的)应用程序的差异和平板电脑(三星Galaxy 10.1)。
I would like to programmatically determine (on the Android platform), if the target device is a phone or a tablet. Is there a way to do this? I tried using Density Metrics to determine the resolution and used resources (images and layouts) accordingly but, it did not turn out well. There are differences when I launch the app on a phone (Droid X) and a tablet (Samsung Galaxy 10.1).
请指教。
推荐答案
您可以使用此code
You can use this code
private boolean isTabletDevice() {
if (android.os.Build.VERSION.SDK_INT >= 11) { // honeycomb
// test screen size, use reflection because isLayoutSizeAtLeast is only available since 11
Configuration con = getResources().getConfiguration();
try {
Method mIsLayoutSizeAtLeast = con.getClass().getMethod("isLayoutSizeAtLeast", int.class);
Boolean r = (Boolean) mIsLayoutSizeAtLeast.invoke(con, 0x00000004); // Configuration.SCREENLAYOUT_SIZE_XLARGE
return r;
} catch (Exception x) {
x.printStackTrace();
return false;
}
}
return false;
}
链接: http://www.androidsnippets.com/how-to-检测-平板设备
这篇关于如何编程方式确定的Android目标设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文