与えられたデバイスがAndroidのタブレットまたは電話であるかどうかを検出したいのですが、シミュレーターで2つを試しましたが、どれも機能しませんでした。両方ともここにあります:
初め
if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE)
{
//code
}
2番
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");
Boolean r = (Boolean) mIsLayoutSizeAtLeast.invoke(con, 0x00000004); // Configuration.SCREENLAYOUT_SIZE_XLARGE
return r;
} catch (Exception x)
{
return false;
}
}
return false;
}